[SDL] Speed In Games

Ryan Wahle wahle at ryu.addell.com
Tue Aug 31 16:36:18 PDT 1999


Won't this slow down the whole game? What if I want one object to go very
fast and one to go very slow without slowing all the objects in the whole
game only go for 40 revolutions a second?

Also, I don't understand how using floating point works because the
cords to blit a sprite to a screen at int. For example, you have xspeed =
.005. Wouldn't that be an int 0... so if you had .007 would also be a int
0 also right?

Sorry I am asking all theses questions.. I'm just trying to get a feel of
how and why a game processes the way it does.

Thanks

On Mon, 30 Aug 1999, Karsten-Olaf Laux wrote:

> on Mon, 30 Aug 1999 Ryan Wahle wrote:
> >I have never used the SDL_GetTicks... Could you explain that alittle more?
> >
> >Thanks
> >
> 
> SDL_GetTicks() returns the number of miliseconds which have passed since you
> have started your application. Here is an excerpt from my mainloop (in fact it
> is part of uapplication.cc from libu)
> Limiting the gameloop to 40 revolutions per second does a great deal on linux
> machines, since if your game is idle, it won't use any cpu cycles,
> since SDL_Delay() gives away cpu time - any notebook users will love you for
> this ;) 
> 
> <<<<<<<<<<<<<<<<<<<
>   Uint32 lastticks;
>   Uint32 tick;
>   Uint32 delta_tick;
> 
>   while(running_)
>     {
>       //Timer stuff
>       tick = SDL_GetTicks();
>       delta_tick = tick - lastticks;
>       lastticks = tick;
>       
>       //limit to 40 revolutions per second (40*25ms = 1 second)
>       if(delta_tick < 25)
>         {
>           SDL_Delay(25 - delta_tick);
>           tick = SDL_GetTicks();
>           delta_tick = delta_tick + tick - lastticks;
>           lastticks = tick;               
>         }
> 
>      ///now delta_tick contains the number of ms since this line was last
>      ///visited..      
> 
>      /// now do the game processing .................
>    
>    } //while      
> 
> >>>>>>>>>>>>>>>>>>>>>>>>>>>
> 
> --
> Karsten-O. Laux           
> klaux at student.uni-kl.de
> http://www.rhrk.uni-kl.de/~klaux
> 




More information about the SDL mailing list