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

Started by
1 comment, last by Light Kuragari 20 years, 8 months ago
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.
Light Kuragari - The Last Nova
Advertisement
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.
Wow, that''s right... thanks, Geoff!! That made a lot of sense, now I have several things to try Thanks again.

Light Kuragari - The Last Nova
Light Kuragari - The Last Nova

This topic is closed to new replies.

Advertisement