为group成员添加动画
1.给group组成员添加animation并发出回调可以像如下这么,但是这样做导致回调函数里,this指向了window而不是这个game
this.targets=this.game.add.group();
this.targets.forEach(function (t) { var playDown=t.animations.play('down'); playDown.onComplete.add(function () {})
2.同时为组成员添加动画可以用callAll
this.targets.callAll('animations.add', 'animations', 'up', [16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0], 17, false); this.targets.callAll('animations.play', 'animations', 'up');3.回调函数传值
经测验,在onComplete里的第三个参数为传值的对象,所以采用本办法用arguments【2】来取传参
var moveGun=this.game.add.tween( this.gun).to( { x: item.x+50}, 2000, Phaser.Easing.Sinusoidal.InOut, true); moveGun.onComplete.add(this.impact,this,1,item);
ShootPlay.prototype.impact=function (item) { var mark=arguments[2]; var myBullet=game.add.image(item.x+50,390,'bullet'); var shooting=this.game.add.tween(myBullet).to( { x:mark.x+70,y:mark.y+50}, 100, Phaser.Easing.Sinusoidal.InOut, true); shooting.onComplete.addOnce(this.playAnimation,this,1,mark) };注意item为当前执行动画的那个精灵