飞机游戏

来源:互联网 发布:炒股最好的软件 编辑:程序博客网 时间:2024/05/01 05:41

先给飞机定一个初始坐标

this._inAnpng.setPosition(cc.winSize.width>>1,(cc.winSize.height>>1)-200);

在给飞机一个点击移动事件

var that = this;var listener = cc.EventListener.create({    event: cc.EventListener.TOUCH_ONE_BY_ONE,    swallowTouches: true,    onTouchBegan: function (touch, event) {        return true;    },    onTouchMoved: function (touch, event) {        var target=that.飞机;        var po = touch.getDelta();        target.x += po.x ;        target.y += po.y ;    },    onTouchEnded:function(touch, event){    }

设置上飞机的子弹坐标  随战机一起移动 并且使子弹发射事件添加计时器

 
//子弹移动var Sp = new cc.Sprite("res/png_3.png");Sp.setPosition(this._inAnpng.x, this._inAnpng.y + 80)this.addChild(Sp);var moveTo = cc.moveBy(2, cc.p(0, cc.winSize.height << 1));Sp.runAction(cc.sequence(moveTo, cc.callFunc(this.removeBullet, this)));
removeBullet:function(target){    target.removeFromParent(true)}
this.schedule(this._dan, 1 / 5, cc.repeatForever, 1);

 

 

 

0 0
原创粉丝点击