What is a good way to draw a particular animation without repeating the sequence? Think of like a spell effect or an explosion sequence.
In the example with Gosu:
@cur_image = @animation[Gosu::milliseconds / @delay % @animation.size]
This causes an animation to repeat, assuming that you keep drawing the object. So the approach I took in the source I've linked to was to establish a time-to-live (ttl) value for the lightning bolt I'm drawing. I specify a 100 millisecond delay (if I understand the formula right) and multiply that by the number of frames (@animation.size). Then, when I first create the object that represents the lightning bolt - I capture the Gosu::milliseconds
value. Each time I call my update() method on the lightning bolt, i check if Gosu::milliseconds
minus the start time is greater than my calculated time-to-live value. What I'm having happen is the lightning bolt ends up repeating some of the first few frames before it stops being drawn.
A few questions:
1) I'm assuming I misunderstand how the formula I've pasted here works - if my animation is repeating a bit. Can you help me identify what I can improve here so the animation only draws each frame once and then leaves?
2) Is there a better way to do this? I know Chingu has a way to tell the animation not to repeat, but I'm still trying to learn how to do it myself before adopting too many tools.
Here is a link to my Github for this test-program: Github Link