十一 手游开发神器 cocos2d-x editor 之音乐和音效
来源:未知 责任编辑:责任编辑 发表时间:2014-02-02 17:45 点击:次
这一节,我将给游戏添加背景音乐和音效;

先在Resources目录下新建一个sounds目录,把准备好的音效复制到该目录下;

打开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);
}
相关新闻>>
- Cocos2d-x 3.2 大富翁游戏项目开发-第二十四部分 彩票开奖
- cocos2d-x开发: 场景实体(entity)管理
- Cocos2d-x虚拟摇杆控制精灵上下左右运动----之游戏开发《赵云要
- Cocos2d-x 3.2 大富翁游戏项目开发-第七部分 获取角色路径_2
- Cocos2d-x 自定义按钮类控制精灵攻击----之游戏开发《赵云要格斗
- Cocos2d-x 3.2 大富翁游戏项目开发-第七部分 获取角色路径_3
- Cocos2d-x 3.2 大富翁游戏项目开发-第八部分 角色按路径行走
- 结合cocos2d-x开发配置sublime text
- cocos2d-x开发: 如何从项目中分离出接口范例
- Cocos2d-x 3.2 大富翁游戏项目开发-第十部分实现人物轮流行走
最新推荐更多>>>
- 发表评论
-
- 最新评论 进入详细评论页>>

![cocos2d_x+lua[2]](/uploads/allimg/131030/110J64609-0-lp.jpg)








