敌机是随机的反方向随机出现的,给敌机添加个敌机精灵.类去实现敌机的基本功能,并且给他附加个消除功能+循环随机出现
var Enemy = cc.Sprite.extend({ ctor: function () { this._super(敌方飞机图片); } });var EnemyLayer = cc.Layer.extend({ ctor: function () { this._super(); this._init(); this.schedule(this._init, 1, cc.repeatForever, 1); }, _init:function() { var difan = new Enemy(); difan.setPosition(cc.winSize.width*Math.random(),cc.winSize.height); var moveTo = cc.moveBy(6, cc.p(0,-cc.winSize.height+20)); difan.runAction(cc.sequence(moveTo, cc.callFunc(this.removeBullet, this))); this.addChild(difan) }, removeBullet:function(target){ target.removeFromParent(true) } });