溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

十一 手游開發神器 cocos2d-x editor 之音樂和音效

發布時間:2020-08-10 23:04:02 來源:網絡 閱讀:512 作者:makeapp628 欄目:游戲開發

這一節,我將給游戲添加背景音樂和音效;


十一 手游開發神器  cocos2d-x  editor 之音樂和音效


代碼下載:http://www.kuaipan.cn/file/id_25348935635744873.htm?source=1



先在Resources目錄下新建一個sounds目錄,把準備好的音效復制到該目錄下;

十一 手游開發神器  cocos2d-x  editor 之音樂和音效


打開MainLayer.js,修改代碼如下:

// // CleanerScoreScene class //  var MainLayer = function () {     cc.log("MainLayer")     this.scoreLabel = this.scoreLabel || {};     this.monster = this.monster || {};     this.score = 123; };  MainLayer.prototype.onDidLoadFromCCB = function () {     if (sys.platform == 'browser') {         this.onEnter();     }     else {         this.rootNode.onEnter = function () {             this.controller.onEnter();         };     }      this.rootNode.schedule(function (dt) {         this.controller.onUpdate(dt);     });      this.rootNode.onExit = function () {         this.controller.onExit();     };      this.rootNode.onTouchesBegan = function (touches, event) {         this.controller.onTouchesBegan(touches, event);         return true;     };      this.rootNode.onTouchesMoved = function (touches, event) {         this.controller.onTouchesMoved(touches, event);         return true;     };     this.rootNode.onTouchesEnded = function (touches, event) {         this.controller.onTouchesEnded(touches, event);         return true;     };     this.rootNode.setTouchEnabled(true); };  MainLayer.prototype.onEnter = function () {     var flowerParticle = cc.ParticleSystem.create("Resources/particles/flower.plist");     flowerParticle.setAnchorPoint(cc.p(0.5, 0.5));     flowerParticle.setPosition(cc.p(60, 160));     flowerParticle.setPositionType(1);     this.monster.addChild(flowerParticle);      cc.AudioEngine.getInstance().playMusic("Resources/sounds/bg_music.mp3", true); }  MainLayer.prototype.monsterMove = function (x, y) {     this.monster.stopAllActions();     cc.AnimationCache.getInstance().addAnimations("Resources/snow_frame.plist");//添加幀動畫文件     var action0 = cc.Sequence.create(cc.MoveTo.create(5, cc.p(x, y)));  //向前移動     var actionFrame = cc.Animate.create(cc.AnimationCache.getInstance().getAnimation("monster"));   //獲取幀動畫     var action1 = cc.Repeat.create(actionFrame, 90000);     var action2 = cc.Spawn.create(action0, action1); //同步動畫     this.monster.runAction(action2); }  MainLayer.prototype.createParticle = function (name, x, y) {     var particle = cc.ParticleSystem.create("Resources/particles/" + name + ".plist");     particle.setAnchorPoint(cc.p(0.5, 0.5));     particle.setPosition(cc.p(x, y));     particle.setPositionType(1);     particle.setDuration(3);     this.rootNode.addChild(particle); }   MainLayer.prototype.onUpdate = function (dt) {     this.score += dt;     this.scoreLabel.setString(Math.floor(this.score)); }  MainLayer.prototype.onExitClicked = function () {     cc.log("onExitClicked"); }   MainLayer.prototype.onExit = function () {     cc.log("onExit"); }  MainLayer.prototype.onTouchesBegan = function (touches, event) {     var loc = touches[0].getLocation(); }  MainLayer.prototype.onTouchesMoved = function (touches, event) {     cc.log("onTouchesMoved"); }  MainLayer.prototype.onTouchesEnded = function (touches, event) {     cc.log("onTouchesEnded");     var loc = touches[0].getLocation();     cc.AudioEngine.getInstance().playEffect("Resources/sounds/bomb.mp3", false);     this.monsterMove(loc.x, loc.y);     this.createParticle("around", loc.x, loc.y); }   


點擊運行;一切OK;


下一篇文章 我會介紹cocos2d-x  editor的懸浮框    筆者(李元友)

資料來源:cocos2d-x  editor


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女