[SDL] Synchronization and fps - mental confusion

Salvatore Di Fazio salvatore.difazio at gmail.com
Wed Sep 27 11:07:05 PDT 2006


Hi guys,
in my own demo I did insert one more sprite.

The first one was moved from the player, the other was moved from the cpu.

Logically the time of interaction between the two "player" is difference.

I read a WaitFrame function in the Sam Lantiga's aliens demo:

------------------------------------------------
void WaitFrame(void)
{
	static Uint32 next_tick = 0;
	Uint32 this_tick;

	/* Wait for the next frame */
	this_tick = SDL_GetTicks();
	if ( this_tick < next_tick ) {
		SDL_Delay(next_tick-this_tick);
	}
	next_tick = this_tick + (1000/FRAMES_PER_SEC);
}

main()
{
  while(1)
  {
    WaitFrame();
    GameFunctions01();
    GameFunctions02();
    GameFunctions03();
  }

}
------------------------------------------------

Okkey I think that this function make a delay if we have a cycle so
fast that it's less than 1 second... right?

How can I move all my sprite in the same time?
How can I calculate the frame rate?

Tnx




More information about the SDL mailing list