frame rate and animation

Started by
2 comments, last by ca_priest 21 years, 4 months ago
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 other...so 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?
...and that's where I saw the leprechaun...he told me to burn things.
Advertisement
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.
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 = 250;// this is in thousandths of a second.<br><br>Then you have a variable in your class that holds the last time the animation was cycled, like so:<br><br>DWORD lastCycleTime;<br><br>Then have a test to see when to change the frame like so:<br><br>if(currentTime > lastCycleTime + frameTime[currentCycle])<br> currentCycle++;<br><br>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 &#111;nly moved the player when you moved to a different frame in the animation.<br><br>If you don't want the player to look like he's "gliding" across the floor, you can add in more frames <img src="smile.gif" width=15 height=15 align=middle><br><br>Hope this helped,<br><br>–Vic– [/source]<br><br><SPAN CLASS=editedby>[edited by - Roof Top Pew Wee &#111;n December 7, 2002 2:19:12 AM]</SPAN>
Thanks alot Pew Wee, it answered my questions exactly. Thanks again for taking the time to give such a complete answer.
...and that's where I saw the leprechaun...he told me to burn things.

This topic is closed to new replies.

Advertisement