Archer3CL Posted January 18, 2015 Share Posted January 18, 2015 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 nowsquash: 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 More sharing options...
ForgeableSum Posted January 18, 2015 Share Posted January 18, 2015 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 More sharing options...
Archer3CL Posted January 19, 2015 Author Share Posted January 19, 2015 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 More sharing options...
horkoda Posted January 19, 2015 Share Posted January 19, 2015 Try replacing sprite.damage(this.inputPower);withsprite.health -= this.inputPower;damage() essentially does the same thing, but also checks whether the sprite is alive (and kills the sprite if the health is below 0, as you know). Link to comment Share on other sites More sharing options...
Recommended Posts