Public Group

SDL Delay

This topic is 3914 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello. I'm wondering if the SDL delay function is appropriate for animation with frames.

Share on other sites
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 on other sites
I'm making a game... Thanks for telling me!

Share on other sites
What kind of technique should you use instead of calling SDL Delay?

Share on other sites
Quote:
 Original post by FILOWhat 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 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 on other sites
Quote:
 Original post by KwizatzIf 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 on other sites
Try this:

// Ask SDL for the time in millisecondsint 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.

• 45
• 12
• 10
• 10
• 9
• Forum Statistics

• Total Topics
631373
• Total Posts
2999629
×