弹出出生有一个星星动画,要在生成坦克前,生成这个动画
// 出生动画,延迟两秒生成坦克
TankWar.prototype.birth = function (id) {
const { BIRTH, BIRTH_CONTAINER } = constants.animations;
const birthContainer = new PIXI.Container();
birthContainer.name = BIRTH_CONTAINER;
for (let i = 0; i < 5; i++) {
const birthAnimation = new PIXI.AnimatedSprite(id[BIRTH]);
birthAnimation.name = `birthAnimation-${i}`;
if (i === 4) {
birthAnimation.position.set(50,20);
} else {
birthAnimation.x = i * 100;
birthAnimation.y = 10;
}
birthAnimation.visible = false;
birthAnimation.animationSpeed = 0.1;
birthAnimation.play();
birthContainer.addChild(birthAnimation);
}
birthContainer.scale.x = 1.2;
birthContainer.scale.y = 1.2;
this.application.stage.addChild(birthContainer);
birthContainer.getChildByName('birthAnimation-4')
console.log(birthContainer.getChildByName('birthAnimation-4'));
birthContainer.getChildByName('birthAnimation-4').visible = true;
setTimeout(() => {
birthContainer.getChildByName('birthAnimation-4').visible = false;
this.createdPlayer(id, 50, 20);
},2000)
};
//生成坦克
TankWar.prototype.createdPlayer = function (animationPosition,x,y) {
console.log(x,y)
const { vx, vy } = defaultSpeed;
this.player = new PIXI.Container();
Object.keys(constants.animations).forEach((item, index) => {
let tankDir = new PIXI.AnimatedSprite(animationPosition[constants.animations[item]]);
tankDir.animationSpeed = 0.2;
tankDir.play();
tankDir.visible = constants.animations[item] === constants.animations.INIT_TANK_DOWN;
tankDir.name = constants.animations[item];
this.player.addChild(tankDir);
});
this.player.life = this.life;
this.player.scale.x = scale.X;
this.player.scale.y = scale.Y;
this.player.vx = vx;
this.player.vy = vy;
this.player.position.set(x,y)
this.application.stage.addChild(this.player);
};
//无敌动画
TankWar.prototype.wudi = function (animationPosition,x,y) {
this.wudiSprite = new PIXI.AnimatedSprite(animationPosition[constants.animations.WUDI])
this.wudiSprite.position.set(x,y);
this.wudiSprite.scale.set(2,2);
// wudiSprite.anchor.set(0.5,0.5);
this.wudiSprite.animationSpeed = 0.15;
this.wudiSprite.play();
this.application.stage.addChild(this.wudiSprite);
}