Archived

This topic is now archived and is closed to further replies.

Light Kuragari

How do I keep 2 or more different things moving on screen at the same time?

Recommended Posts

I''ve been trying to realize how can I make two different sprites move independently in time, for example... if you have a game where an enemy is moving and it´s animation is being processed, and then you press a key, the animation of your character has to start, while the enemie´s animation isn''t over... how do you do that? By the way... I´m writing on C.

Share this post


Link to post
Share on other sites
Store the number of the current animation frame that each object being displayed is current at. When you draw the screen, pick an animation frame based on your stored number and use it to draw the object. Repeat for all objects. Then increment the number of the animation frame for all objects. If the number goes past the last frame for a given object, set it to the number of the first frame, so you''ll be looped back for the next screen draw. You could also determine how long it''s been since you last updated the animation frame numbers, and only increment the numbers if a certain amount of time has passed, thereby making animations that change at the same speed, regardless of the framerate. There are various other things to try, like having an ''idle'' animation frame that if the object''s frame number is set for, then the frame number isn''t updated, so you stay on the same animation frame until something else changes the current frame (like starting to move). You could also make this an idle loop instead of just a single frame.

Share this post


Link to post
Share on other sites