弹出出生有一个星星动画,要在生成坦克前,生成这个动画

    1. // 出生动画,延迟两秒生成坦克
    2. TankWar.prototype.birth = function (id) {
    3. const { BIRTH, BIRTH_CONTAINER } = constants.animations;
    4. const birthContainer = new PIXI.Container();
    5. birthContainer.name = BIRTH_CONTAINER;
    6. for (let i = 0; i < 5; i++) {
    7. const birthAnimation = new PIXI.AnimatedSprite(id[BIRTH]);
    8. birthAnimation.name = `birthAnimation-${i}`;
    9. if (i === 4) {
    10. birthAnimation.position.set(50,20);
    11. } else {
    12. birthAnimation.x = i * 100;
    13. birthAnimation.y = 10;
    14. }
    15. birthAnimation.visible = false;
    16. birthAnimation.animationSpeed = 0.1;
    17. birthAnimation.play();
    18. birthContainer.addChild(birthAnimation);
    19. }
    20. birthContainer.scale.x = 1.2;
    21. birthContainer.scale.y = 1.2;
    22. this.application.stage.addChild(birthContainer);
    23. birthContainer.getChildByName('birthAnimation-4')
    24. console.log(birthContainer.getChildByName('birthAnimation-4'));
    25. birthContainer.getChildByName('birthAnimation-4').visible = true;
    26. setTimeout(() => {
    27. birthContainer.getChildByName('birthAnimation-4').visible = false;
    28. this.createdPlayer(id, 50, 20);
    29. },2000)
    30. };
    1. //生成坦克
    2. TankWar.prototype.createdPlayer = function (animationPosition,x,y) {
    3. console.log(x,y)
    4. const { vx, vy } = defaultSpeed;
    5. this.player = new PIXI.Container();
    6. Object.keys(constants.animations).forEach((item, index) => {
    7. let tankDir = new PIXI.AnimatedSprite(animationPosition[constants.animations[item]]);
    8. tankDir.animationSpeed = 0.2;
    9. tankDir.play();
    10. tankDir.visible = constants.animations[item] === constants.animations.INIT_TANK_DOWN;
    11. tankDir.name = constants.animations[item];
    12. this.player.addChild(tankDir);
    13. });
    14. this.player.life = this.life;
    15. this.player.scale.x = scale.X;
    16. this.player.scale.y = scale.Y;
    17. this.player.vx = vx;
    18. this.player.vy = vy;
    19. this.player.position.set(x,y)
    20. this.application.stage.addChild(this.player);
    21. };
    1. //无敌动画
    2. TankWar.prototype.wudi = function (animationPosition,x,y) {
    3. this.wudiSprite = new PIXI.AnimatedSprite(animationPosition[constants.animations.WUDI])
    4. this.wudiSprite.position.set(x,y);
    5. this.wudiSprite.scale.set(2,2);
    6. // wudiSprite.anchor.set(0.5,0.5);
    7. this.wudiSprite.animationSpeed = 0.15;
    8. this.wudiSprite.play();
    9. this.application.stage.addChild(this.wudiSprite);
    10. }