Jump to content

Change sprite.damage(); behavior


Archer3CL
 Share

Recommended Posts

Hi guys. I was wondering if i can change the sprite.damage() behavior.

 

For example, I want to play the 'die' animation if sprite is dead but if i use damage() as the doc says 

 

 

If health is then taken below or is equal to zeroSprite.kill is called.

 

And the code im using right now

squash: function(sprite, pointer){        sprite.damage(this.inputPower);        if(!sprite.alive){            sprite.body.velocity.y = 0;            sprite.animations.play('die', 2, false, true);        }},

 So do i have to implement my own method? Thanks

Link to comment
Share on other sites

Have you tried listening to the Sprites.events.onKilled signal? You should be able to override phaser from setting the visible and exists properties to false. Set those properties true and run your animation in an onKilled listener function. http://docs.phaser.io/Phaser.Signal.html#add 

 

If that doesn't work then yeah, I would write your own method. All damage() does is subtract from the .health property (and kill the sprite which you don't want). 

Link to comment
Share on other sites

Have you tried listening to the Sprites.events.onKilled signal? You should be able to override phaser from setting the visible and exists properties to false. Set those properties true and run your animation in an onKilled listener function. http://docs.phaser.io/Phaser.Signal.html#add 

 

If that doesn't work then yeah, I would write your own method. All damage() does is subtract from the .health property (and kill the sprite which you don't want). 

 

Well gues ill be doing my own method. Thanks

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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