Jump to content
  • Advertisement
Sign in to follow this  
P32Ay

SDL_GetTicks erratic motion thingy

This topic is 3792 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!