子弹碰撞到边界需要出现爆炸动画,然后子弹消失,出现爆炸。
难点是在指定位置出现爆炸点
这里可以通过重新sprite的锚点来确定爆炸位置。
TankWar.prototype.removeGun = function () {
const {gun} = this;
const getGun = gun.getChildAt(0);
gun.removeChildren();
this.boom(getGun.x,getGun.y)
}
TankWar.prototype.boom = function (x,y) {
const {BOOM} = constants;
const id = this.loader.resources.spaceship.spritesheet.animations;
console.log(id[BOOM],BOOM)
const boom = new PIXI.AnimatedSprite(id[BOOM]);
boom.animationSpeed = 0.2;
boom.play();
boom.name= BOOM
boom.loop = false;
boom.onComplete = () => {
const getBOOM = this.application.stage.getChildByName(BOOM);
this.application.stage.removeChild(getBOOM);
}
boom.scale.x = 2;
boom.scale.y = 2;
boom.anchor.set(0.5,0.5);
boom.x = x;
boom.y = y;
this.application.stage.addChild(boom);
}