Advertisement Jump to content


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


frame rate and animation

This topic is 5885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If im running my game loop at 60fps, but i only want to cycle through 4 frames of animation during that time period...what am i supposed to do in between animations? For example i have a sprite and i want him to move 1 tile in 1 second. During that one second the sprite changes from standing still, to one leg forward, standing still, other leg forward and back to standing still. Each of these animations i would assume should take place at equal intervals from each the sprite changes every 1/15 of a second. But during all the other loops, what is going on?? Should the sprite stand still, or should he move but without changing the sprite itself? Anyone know what i could do here?

Share this post

Link to post
Share on other sites
well if you only have 4 different positions for your character
you should do what you said, move the sprite on an interpolated
value and do not change the sprite until the time has come.

Share this post

Link to post
Share on other sites
Here's how I hadled my sprite animation. I have a class called spriteInfo which obviously holds info on sprites.

What you want to do is have a variable for position, say X and Y. Then have an X and Y velocity. Then every frame you could have:

mySpriteInfo.x += mySpriteInfo.xVelocity*difference;
mySpriteInfo.y += mySpriteInfo.yVelocity*difference;

Difference would be calculated by getting the current time at the beginning of your game loop, then subtracting it from the time at the end of your game loop.

This will handle movement of your sprite. As for animation, in my sprite class, I also have the following:

DWORD frameTime[32];

What you could do here is since you have 5 frames that you want to cycle, you could figure out how long you want each frame to show up. Since you said you have 4 frames of animation, and they cycle every second, you would initialize the array like so:

for(int i = 0; i < 4; i++)
frameTime[ i] = 250;// this is in thousandths of a second.

Then you have a variable in your class that holds the last time the animation was cycled, like so:

DWORD lastCycleTime;

Then have a test to see when to change the frame like so:

if(currentTime > lastCycleTime + frameTime[currentCycle])

Sorry I took so long to answer your question. Now to answer it: This code will keep each frame drawn for 1/4th of a second. In the mean time, the player will continue to move across the ground, even though the frame is not cycled. This is desireable, because if you didn't do this, the player would "jump" each time the animation was changed. It would look a lot worse if you only moved the player when you moved to a different frame in the animation.

If you don't want the player to look like he's "gliding" across the floor, you can add in more frames

Hope this helped,

--Vic-- [/source]

[edited by - Roof Top Pew Wee on December 7, 2002 2:19:12 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!