Skip to main content
GameDev.net gamedev.net
🔒 Locked

Frame Independent Motion/Animation in SDL

Started by MrTheFoxx Jan 29, 2012 at 6:46 PM 3 replies 1.9k views
Original Post
MrTheFoxx
MrTheFoxx
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.
djsteffey
djsteffey
use the SDL timer class to get the elapsed seconds since last frame

then

x_pos += delta_time * 40.0f;
MrTheFoxx
MrTheFoxx
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...
21st Century Moose
21st Century Moose
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. 
MrTheFoxx
MrTheFoxx
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!

Topic Locked

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

Sign in to reply to this topic.