[SDL] Speed In Games

Karsten-Olaf Laux klaux at student.uni-kl.de
Tue Aug 31 17:30:58 PDT 1999


on Mit, 01 Sep 1999 Ryan Wahle wrote:
>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?
>
The 40 updates per second has nothing to do with the speed of any moving
objects; it means that the screen is updated at a maximum rate of 40 times per
second. Every update rate above 30 gives us humans the impression of smooth
movement.
In uclient, which is a client for an online roleplaying game, I use
only 20 screen updates per second, which provides still very smooth movements
of the characters.

>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?
>
As Stuart mentioned, you will also have to store the positions as floats, too.
Think of the floats as the coordinates in your gameworld. When drawing on the
screen you have to convert game-coordinates to pixel coordinates....

float fx, fy; 
int x,y;

//simulation coordinates
fx = fx + vx * delta_t; 
fy = fy + vy * delta_t;

//screen coordinates
x = (unsigned int)(fx + 0.5);
y = (unsigned int)(fy + 0.5);

>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
>


--
Karsten-O. Laux           
klaux at student.uni-kl.de
http://www.rhrk.uni-kl.de/~klaux




More information about the SDL mailing list