Frame Independent Motion/Animation in SDL

Started by
3 comments, last by MrTheFoxx 12 years, 2 months ago
I've done a lot of research to find nothing, so I'm posting here. Here goes nothing.

I have two images: a red circle and a blue circle. I have some controls set up. I want the sprite to swap between the red circle and the blue circle every half second and I want it to move across the screen at the same speed of forty pixels per second, both independent from the frame rate. Can anyone give me a minimal example of this being done in C (not C++ or C#... C)? Thank you. :)
Advertisement
use the SDL timer class to get the elapsed seconds since last frame

then

x_pos += delta_time * 40.0f;
I found something about that while I was Googling, but it has to do with C++. The timer class likely isn't present in C itself because C++ is C with Classes. There has to be some other alternative in C to what is available in C++. Or maybe I could program my own time calculator and integrate that in there...
SDL_GetTicks will give you the number of elapsed milliseconds.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Thanks! So I can set up some if statements and if the time elapsed is equal to or beyond a certain value, change the animation frame for the player and/or the position? Good. Thanks! :)

This topic is closed to new replies.

Advertisement