Sign in to follow this  

Problem with delta time

This topic is 4715 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
while(TRUE)
{
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
Quote:
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

This topic is 4715 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this