Cocos2d-x《雷电大战》(3)-子弹无限发射
2017-07-18 10:46
232 查看
Cocos2d-x《雷电大战》(3)-子弹无限发射
作者想让飞机能发子弹
1 资源
var res = {
///....
BULLET1:'res/bullet1.png',
//.....
};
2 有调度的airplane
var Airplane = cc.Layer.extend({
ctor:function (){
//......
me.batchNode=new cc.SpriteBatchNode(res.BULLET1);
me.batchNode.retain();
me.bullteId=0;
me.bullteSpeed=500;
me.bulltes={};
me.schedule(me.fire, 0.5);
//......
return true;
},
onExit:function(){
me.batchNode.release();
},
fire:function(dt){
var me=this;
var sp=new cc.Sprite(me.batchNode.getTexture());
var point=me.air.getPosition();
var px=point.x;
var py=point.y + me.air.getContentSize().height + 20;
sp.setPosition(px,py);
var bid=me.bullteId++;
sp.setTag(bid);
me.addChild(sp,-1);
var flyLen= cc.winSize.height - py;
var duration = flyLen / me.bullteSpeed;
var action=new cc.Sequence([
new cc.MoveTo(duration,cc.p(px,cc.winSize.height)),
new cc.CallFunc(function(bullet,id){
delete this.bulltes[id];
this.removeChildByTag(id);
},me,bid)
]);
sp.runAction(action);
me.bulltes[bid]=sp;
}
});
作者想让飞机能发子弹
1 资源
var res = {
///....
BULLET1:'res/bullet1.png',
//.....
};
2 有调度的airplane
var Airplane = cc.Layer.extend({
ctor:function (){
//......
me.batchNode=new cc.SpriteBatchNode(res.BULLET1);
me.batchNode.retain();
me.bullteId=0;
me.bullteSpeed=500;
me.bulltes={};
me.schedule(me.fire, 0.5);
//......
return true;
},
onExit:function(){
me.batchNode.release();
},
fire:function(dt){
var me=this;
var sp=new cc.Sprite(me.batchNode.getTexture());
var point=me.air.getPosition();
var px=point.x;
var py=point.y + me.air.getContentSize().height + 20;
sp.setPosition(px,py);
var bid=me.bullteId++;
sp.setTag(bid);
me.addChild(sp,-1);
var flyLen= cc.winSize.height - py;
var duration = flyLen / me.bullteSpeed;
var action=new cc.Sequence([
new cc.MoveTo(duration,cc.p(px,cc.winSize.height)),
new cc.CallFunc(function(bullet,id){
delete this.bulltes[id];
this.removeChildByTag(id);
},me,bid)
]);
sp.runAction(action);
me.bulltes[bid]=sp;
}
});
相关文章推荐
- Cocos2d-x《雷电大战》(3)-子弹无限发射
- Cocos2d-x《雷电大战》(3)-子弹无限发射
- cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第十步---发射子弹&怪物受伤---所有源码和资源完结下载
- cocos2d-x入门(4)-英雄发射子弹和碰撞检测
- Cocos2d-x--发射多发子弹
- Cocos2d-x《雷电大战》-双层地图无限滚动 推荐
- Cocos2d-x《雷电大战》(1)-双层地图无限滚动
- Cocos2d-x《雷电大战》(1)-双层地图无限滚动
- Cocos2d-x《雷电大战》(4)-策略模式实现不同子弹切换!!
- cocos2d-x学习笔记之发射子弹技能
- cocos2d-x发射子弹
- cocos2d-x SimpleGame(3)如何发射子弹
- Cocos2d-x《雷电大战》(4)-策略模式实现不同子弹切换!!
- (6) cocos2d-x发射子弹
- 在cocos2d中使tilemap地图有无限循环的效果
- Unity发射子弹
- 角色子弹的发射(小龙喷火篇)
- cocos2d-x游戏开发(三)无限滚动地图
- cocos2d-x 无限地图滚动
- cocos2d-x 精灵(如子弹)的去除