Jump to content
  • Advertisement
Sign in to follow this  
Fire Wind

SDL Delay

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

Advertisement
Not if your game will feature many such animations concurrently.

If you were making a program where the animation filled the entire window (like a simple movie player) then you could get away with it.

Share this post


Link to post
Share on other sites
Quote:
Original post by FILO
What kind of technique should you use instead of calling SDL Delay?


Check this out ;) :
http://www.gamedev.net/community/forums/topic.asp?topic_id=69074

Share this post


Link to post
Share on other sites
If you're using a delay function in your animation code, your code is wrong, instead get the current time and subtract the last time recorded, if enough time has passed between the 2 samples, switch frame, save current time as last time and repeat.

Use SDL_GetTicks() to get the number of milliseconds since the SDL library initialization, since you're working with deltas, you don't need the actual "current time".

Share this post


Link to post
Share on other sites
Quote:
Original post by Kwizatz
If you're using a delay function in your animation code, your code is wrong, instead get the current time and subtract the last time recorded, if enough time has passed between the 2 samples, switch frame, save current time as last time and repeat.

Use SDL_GetTicks() to get the number of milliseconds since the SDL library initialization, since you're working with deltas, you don't need the actual "current time".


Thanks for the advice guys. This is what I am currently doing:

// Ask SDL for the time in milliseconds
int tick = SDL_GetTicks();

if (tick <= gLastTick)
{
SDL_Delay(1);
return;
}

while (gLastTick < tick)
{
gLastTick += 1000 / ICSFPS;
}


where ICSFPS is defined like so in the .header:

//iterations per second
#define ICSFPS 10

This kind of works but I still have issues concerning things moving too fast. Thanks again for all the help

Share this post


Link to post
Share on other sites
Try this:


// Ask SDL for the time in milliseconds
int tick = SDL_GetTicks();

if ((tick - gLastTick)>100) // one frame every 100 milliseconds, IE 10 frames per second
{
/* set next frame as current frame */
gLastTick=tick;

}
/* render current frame */




you may want to initialize gLastTick to zero so the first time the code is run an update is performed.

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!