animation and flow timers
Posted: Thu Jun 02, 2011 9:10 pm
Hi, I'm just starting out with love2d and i have a question about timers.
In a regular shoot em up the player flickers and is invincible for a couple of seconds after losing a life.
It was easy to implement this feature but i wonder if there is a better/smarter way to do this.
This is what i do in the update routine of the player object:
When the player loses a life; i set invincible to true. Then i switch between 2 images for for two seconds to mimick the flickering effect.
In the collision detection routine i check for player.invincible to ignore collisions.
Is this how i should do stuff like this or are there better ways?
Regards, TM
In a regular shoot em up the player flickers and is invincible for a couple of seconds after losing a life.
It was easy to implement this feature but i wonder if there is a better/smarter way to do this.
This is what i do in the update routine of the player object:
Code: Select all
if invincible then
invincible_indicator_timer = invincible_indicator_timer + 1 * dt
if invincible_indicator_timer <= 2 then
invincible_timer = invincible_timer + 1 * dt
if invincible_timer >= 0.05 then
active_image = 'invincible'
invincible_timer = 0
else
active_image = 'normal'
end
else
active_image = 'normal'
invincible = false
invincible_indicator_timer = 0
end
end
In the collision detection routine i check for player.invincible to ignore collisions.
Is this how i should do stuff like this or are there better ways?
Regards, TM