Jump to content
  • Advertisement
Sign in to follow this  
Daniel Miller

Problem with delta time

This topic is 5027 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

I've been trying to get smooth animation using the change in time each frame. However, my timer (SDL_GetTicks()) isn't accurate enough to register any difference frame to frame. How do I get around this? Find the average every 3 or so frames?

Share this post

Link to post
Share on other sites
this is what i do

// used in calculating the time delta
ltime = SDL_GetTicks();

// use exit(0) to break out of this loop
SDL_Event event;

// calculate the time delta (time)
unsigned int ctime = SDL_GetTicks();
float time = (float)(ctime-ltime)/1000.0f;
ltime = ctime;

it should work

edit: also are all of your positions floats

Share this post

Link to post
Share on other sites
Original post by Daniel Miller
My positions aren't floats... >.<

Thanks a lot! :)

For time based movement to work smoothly, they really should be floats you can cast them to ints later for screen rendering if needed.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!