1 decade ago
by Gamma
I noticed that whenever my player touches an enemy the health bar simply goes all the way down to 0 and the player loses a life. How do I make it so that the player receives damage from enemies when colliding with them, say 10 health points or so.
I believe I'd have to do something with either the player's update or the enemies update...I'm not sure.
1 decade ago
by dominic
It depends on your game how you want to handle this. You could throw the player back a few pixels so he no longer collides with the enemy, or use a timer to make him invincible for a few seconds.
Example with the timer:
init: function( x, y, settings ) {
this.parent( x, y, settings );
// ...
this.invincibleTimer = new ig.Timer();
},
receiveDamage: function( amount, from ) {
if( this.invincibleTimer.delta() > 0 ) {
// if we can take damage right now, call the parent
// function to reduce health
this.parent( amount, from );
// make invincible for two seconds
this.invincibleTimer.set(2);
}
}
1 decade ago
by Gamma
Perfect! It worked just fine. This method is way better, I was going to experiment by making the player lose a certain amount of hp, but your way is better. Thank you for the help, very much appreciated. :)
Page 1 of 1
« first
« previous
next ›
last »