Flicker for life
When making a game using melonjs I have not been able to find anything that will prevent the user from taking damage for a period of time after an event occurs. It might be useful to have a life variable defined somewhere. I have noticed that some of the examples the player just dies after they collide with an enemy. It might make the game better if there was a way to have multiple hits before the player dies without having to declare a large variable to keep track of the damage that has occurred.
Hum , i don't have the example in mind but im pretty sure they is already a flicker flag that you can use to define if your entity take or not damage, else and this how i work i create flags for my needs , like onground, invincible , etc ... you just have to code the comportment in each case, hope this help a little. Le 11 mars 2015 21:53, "snake" [email protected] a écrit :
When making a game using melonjs I have not been able to find anything that will prevent the user from taking damage for a period of time after an event occurs. It might be useful to have a life variable defined somewhere. I have noticed that some of the examples the player just dies after they collide with an enemy. It might make the game better if there was a way to have multiple hits before the player dies without having to declare a large variable to keep track of the damage that has occurred.
— Reply to this email directly or view it on GitHub https://github.com/melonjs/melonJS/issues/674.
@dispositional The me.Sprite.flicker method accepts a callback, which allows you to disable collisions with enemy entities temporarily, and re-enable collisions in the callback.
// Disable collisions with enemies
this.body.setCollisionMask(me.collision.types.WORLD_SHAPE);
// Flicker for 1 second, then enable collisions
this.renderable.flicker(1000, function () {
this.body.setCollisionMask(
me.collision.types.WORLD_SHAPE |
me.collision.types.ENEMY_OBJECT
);
}.bind(this));
This code assumes you are setting the body.collisionType property on your enemy entities to me.collision.types.ENEMY_OBJECT
You are free to store and manage the health variable yourself. In combination with disabling collisions temporarily, you don't need to do any other tricky logic; just decrement the health when there's a collision, and kill the player when health is gone.
@dispositional Any comments here?
Actually that is exactly what I was looking for @parasyte. I got it woking like this: this.renderable.flicker(1000, function () { this.body.setCollisionMask( me.collision.types.WORLD_SHAPE ); game.data.life -= 1; this.body.setCollisionMask(me.collision.types.ALL_OBJECT); }.bind(this));
and it worked exactly like I wanted it to.