Skip to main content
gamedev.net
🔒 Locked

Sprites animation.

Started by Dospro Apr 12, 2006 at 9:04 PM 2 replies 700+ views
Original Post
Dospro
Dospro
Hi. I'm trying to make a new game and well, it is everything prepeared just to begin it except one thing. How is animation made? I have always had problems understanding how 2D animation works in games, once understood, i will continue my game. I was thinking to manage it by timers, i mean, set a timer to 10ms (this means that one action will happen every 10 ms). So each 10 ms i could change the graphic that is being painted. But then i thought that this wont work, because some sprites are more fluent than others, i mean, some must change the image faster than others. So what technich do you think is the best for sprite animation? Im really desperated.
Ravuya
Ravuya
My sprite class carries a "frame delay" timer and an update method that increments the timer, checks to see if it's gone over the "frame delay" and advances the frame if so.

This way I can have a variable maximum "frame delay" (150ms for my running animation and 300ms for my jumping animation). Then I just loop over the objects that should be animating and increment their internal animation timers with the game's delta timer.
Dospro
Dospro
Sorry, can you explain it a little bit better, because i really didn't understand.
SelethD
SelethD
Each object 'sprite' will have a variable 'float fDelay' to tell it how long before changing to the next animation picture. This delay can be different for each object 'sprite'

So I have a sprite of the player walking, this will have a delay of 150ms, so every 150 ms the sprite draws another frame in the animation

Then I have a sprite of a glowing sword (this needs to animate faster) so we have a delay of 100 ms, so every 100 ms it animates another frame.

Every time the program goes once through the game loop, it tells the objects 'sprites' how long it has been since last time through the loop. The objects 'sprites' keep count of how long since they last changed animation frames, and if its been longer than their delay vairable states, then they cange animation frames, and they reset their counter and wait again.

lfc = how long its been since last animation frame was changed
dc = delay counter, telling how long we dealy until we cange frames
tmr = how long since last time we ran through the game loop

// start game loop
trm = current time - last time
//loop through sprites
lfc = lfc + tmr
if (lfc > dc) change animation frame, and clear lfc to 0
// draw sprites
//end sprite loop
//end game loop

Hope that helps :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.