Sign in to follow this  
P32Ay

SDL_GetTicks erratic motion thingy

Recommended Posts

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();

Share this post


Link to post
Share on other sites
I'm a moron. I just stored the current ticks in a variable instead of calling it succesively. Now it works.
Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this