SDL_GetTicks erratic motion thingy

Started by
0 comments, last by P32Ay 16 years, 1 month ago
Hey there, here's a snippet from a program I'm doing, and for some reason the object moves erratically. Why?

int xvel,yvel;
if(merect.x!=goalx){if(merect.x<goalx){xvel=1;}else xvel=-1;}else xvel=0;
if(merect.y!=goaly){if(merect.y<goaly){yvel=1;}else yvel=-1;}else yvel=0;
x+=xvel*(movementspeed*((SDL_GetTicks()-lastupdate)/1000.0f));
y+=yvel*(movementspeed*((SDL_GetTicks()-lastupdate)/1000.0f));
merect.x=(int)x;
merect.y=(int)y;
printf("%f %i\n",lastupdate/1000-SDL_GetTicks()/1000,merect.x);			
lastupdate=SDL_GetTicks();
Advertisement
I'm a moron. I just stored the current ticks in a variable instead of calling it succesively. Now it works.
Thanks!

This topic is closed to new replies.

Advertisement