Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

9 years ago by NeilHighley

Hi,

I'm trying to insert a death animation before kill is called and after receiveDamage is checked.

I have tried adding an onAnimationStopped callback to the death animation but it can't find the entity in the kill command.

e.g.

in Animation.js;

if( this.stop && this.loopCount > 0 ) {
-----
this.onAnimationStopped.call();//callback
}
else {
---
}

and in the entity child class (the enemy sprite);

kill:function(){
this.anims.die.onAnimationStopped=this.onDied; //hookup the callback
this.currentAnim=this.anims.die;
},
onDied:function(){
ig.game.removeEntity( this);
// alert("he died");
},

The alert is fired when I uncomment it, but I can't see the scope to remove the entity.

Can anyone help?

Neil

9 years ago by jminor

I recommend spawning a separate entity that displays the death animation. That way your enemy sprite dies right away and is replaced with an explosion or whatever. The logic for each can be kept separate which makes them each simpler.

9 years ago by NeilHighley

cool, and how do I make that entity kill itself after the death animation has run its course?

9 years ago by NeilHighley

Thanks for your help jMinor, here is what I did.

I spawned a new, death, Entity during the extended kill function of my sprite Entity.

In that death entity, I set the death animation to stop, by adding a true after the frame array.
Then during the "update" extended function, I checked for loopCount>0, which means that the animation has got to the end of the first loop.

Then , I simply called kill on the death entity.

e.g.

update: function() {
if(this.anims.die.loopCount>0){
this.kill();
}else{
this.parent();
}
}

I hope this helps one y'all.

9 years ago by jminor

Nice. You could also use an ig.Timer.
Page 1 of 1
« first « previous next › last »