Santiago Posted October 2, 2017 Share Posted October 2, 2017 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 More sharing options...
samme Posted October 2, 2017 Share Posted October 2, 2017 Yes, you need to set player.exists=true when playing the animation and then exists=false again when the animation is done. Link to comment Share on other sites More sharing options...
Santiago Posted October 2, 2017 Author Share Posted October 2, 2017 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 More sharing options...
Santiago Posted October 2, 2017 Author Share Posted October 2, 2017 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 More sharing options...
Santiago Posted October 3, 2017 Author Share Posted October 3, 2017 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 More sharing options...
Recommended Posts