Jump to content

Need help playing death animation


Santiago
 Share

Recommended Posts

Hello! I want to do a death animation but I can't get it, last thing I tried was using events, but I need some help here

I was doing this on the create function:

this.player.events.onKilled.add(function(){this.player.animations.play('death')}, this);

But it seems to do nothing, would be because the sprite is already killed? I am killing the sprite by damage() method. I don't know what else to do! And I can't find anything useful on Google

Hope you can help me out!

Link to comment
Share on other sites

8 minutes ago, samme said:

Yes, you need to set player.exists=true when playing the animation and then exists=false again when the animation is done.

I'm doing this:

this.death= this.player.animations.add('death', Phaser.Animation.generateFrameNames('death_', 1, 10), 5, true);

this.player.events.onKilled.add(function(){
            this.player.exists = true;
            this.player.animations.play('death');
            if(this.death.onComplete){
                this.player.exist = false;
            }
        }, this)

Now the player still there, but the animation is not playing. I have corroborated that the animation is working, is there anything I'm doing wrong?

Link to comment
Share on other sites

I've corrected my mistake in the last exists, but now it just disappear, and if I take out the if clause the behaviour is the same as recently, still there, existing.

this.death= this.player.animations.add('death', Phaser.Animation.generateFrameNames('death_', 1, 10), 5, true);

this.player.events.onKilled.add(function(){
            this.player.exists = true;
            this.player.animations.play('death');
            if(this.death.onComplete){
                this.player.exists = false;
            }
        }, this)

 

Link to comment
Share on other sites

If is useful for someone, I'm posting the solution I found:

this.player.events.onKilled.add(function(){
            
           var death = this.game.add.sprite(this.player.body.x,this.player.body.y,'vikingoAnim');

            //Here I add my animation         

            death.animations.add('death', Phaser.Animation.generateFrameNames('death_', 1, 10), 7, false);
            
           //I put the animations.play in the die variable            
 
            die = death.animations.play('muerte');
            
           //Kill animation when completes
 
            die.killOnComplete = true;
                      
        }, this);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...