[SDL] does SDL timer sussystem have pause an restart timer function ??

James Turk james at conceptofzero.net
Fri Oct 18 14:26:01 PDT 2002


For "pausing" I would recommend keeping track of the time paused.

This can be done in a number of ways, I'll show a simple way here to
give you the idea:


Uint32 timePaused=SDL_GetTicks(),pausedTime;	//at the beggining

void Pause()
{
	pausedTime = SDL_GetTicks();
}

void Restart()
{
	timePaused = SDL_GetTicks();
}

void Unpause()
{
	timePaused += SDL_GetTicks()-pausedTime;
}

Uint32 GetTime()
{
	return SDL_GetTicks()-timePaused;
}

timePaused is used to keep track of the total time paused
pausedTime is the time the application was paused (yes, i should have
named it something else)

Also if you use this code I'd say to use a boolean value to check if the
timer is actually paused so you dont mess up your timer by unpausing.

My project ZEngine http://sourceforge.net/projects/zengine/ has a
relatively complete time system and class.  Feel free to use some of my
source (or the entire engine) In your own programs.



leolarrel wrote:
> or , can you tech me how to do myself?
> 
> Thank you very mach. 
> 
> 
> -----------------------------------------------------------------
> < 每天都 Yahoo!奇摩 >  www.yahoo.com.tw
> 




More information about the SDL mailing list