cocos2d-js飞机项目大致逻辑


1.创建拖拽侦听,使得可以控制己方飞机的飞行,注意检查飞机飞出了屏幕的问题
var a = 10
        a = cc.clampf(a, 20,50)            →clampf是比较传入的三个值,a接近哪个值,就输出哪个值比如这个例子输出20
        cc.log(a)
var a = cc.p(0,30)
        a = cc.pClamp(a, cc.p(10,10),cc.p(20,20))            →pClamp比较三个坐标,首先横坐标和谁相近就输出哪个的横坐标,纵坐标一样,比如这个例子
        cc.log(a.x, a.y)                                                           输出(10,20)
2.创建schedule,每隔1秒在飞机当前位置创建一个向上直线飞行的子弹(子弹的清除)
① 飞机用schedule 定期发出 子弹 的EVENT
this.schedule(function(){cc.eventManager.dispatchCustomEvent(MY_FLY_PLANE,that.getPosition())},0.2,cc.REPEAT_FOREVER)
②子弹Layer收到event,对子弹进行添加
cc.eventManager.addCustomListener(MY_FLY_PLANE,this._makeBullet.bind(this))
_makeBullet:function(event){
    var pos = event.getUserData();
    var sp = new BulletSprite();
    sp.setPosition(pos.x,pos.y);
    this.addChild(sp);
},
3.思考如何能在子弹离开屏幕的时候将其移除
this.runAction(cc.sequence(cc.moveBy(1, cc.p(0, cc.winSize.height + 20)),
            cc.callFunc(this.removeBullet,this)))
removeBullet:function(target){
        target.removeFromParent(true)
    },
4.在屏幕上方外随机创建敌方飞机,敌方飞机会随机飞行
①添加敌方飞机
this.schedule(this._makeEnEmyPlane,2,cc.REPEAT_FOREVER,0.00001);
_makeEnEmyPlane:function(){
    var sp = new EnEmyPlaneSprite();
    sp.setAnchorPoint(0,0);
    sp.setPosition(cc.winSize.width*Math.random(),cc.winSize.height+100);
    this.addChild(sp);
},
②飞机进行移动和移除处理
var move = cc.moveTo(5,cc.p(cc.winSize.width*Math.random(),-100));
this.runAction(cc.sequence(move,cc.callFunc(this._removeEnEmyPlane,this)))
5.实现子弹和敌方飞机的碰撞
首先敌方飞机抛出自身给子弹管理层子弹管理层进行碰撞检测,从而删除碰撞的子弹和敌方飞机
6.飞机爆炸特效
①加载plist文件cc.spriteFrameCache.addSpriteFrames(res.animation_plist);
②把爆炸图片添加在数组里面
var mExplodeFrames = [];
        for (var i=1;i<17;i++)
        {
            var frame = cc.spriteFrameCache.getSpriteFrame("explosion_"+("00"+i).slice(-2)+".png");
            mExplodeFrames.push(frame);
        }
        var anim = new cc.Animation(mExplodeFrames, 0.04);
③添加新的精灵承载爆炸动画
        var sp = new cc.Sprite()
        sp.setPosition(touch.getLocation()) //点击的位置播放动画
        that.addChild(sp)
        sp.runAction(cc.sequence(cc.animate(anim), cc.fadeOut(0.5))) 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值