[SDL] Speed In Games
wahle at ryu.addell.com
Sun Aug 29 23:38:37 PDT 1999
I have never used the SDL_GetTicks... Could you explain that alittle more?
On Mon, 30 Aug 1999, Karsten-Olaf Laux wrote:
> on Mon, 30 Aug 1999 Ryan Wahle wrote:
> >Hi, does anyone know of a way to control the speed at which an object
> >moved. I can do the x++ and the y++ but after a x and y = 3 it's just way
> >to fast to play....
> >does anyone have any ideas to implement this?
> what about the following:
> float vx = 0.001; // the horizontal speed component in pixels / ms
> float vy = 0.0005; // the horizontal speed component in pixels / ms
> unsigned int x,y; // the position in pixels
> unsigned int delta_t; // time since last position update in ms
> //(... SDL_GetTicks())
> x += (unsigned int)(vx * delta_t + 0.5);
> y += (unsigned int)(vy * delta_t + 0.5);
> ok, it uses floating point arithmetics, which might be replaced by fixed point
> the +0.5 converts float to integer more precisely. (as long as the values > 0)
> Karsten-O. Laux
> klaux at student.uni-kl.de
More information about the SDL