Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

Java whats wrong with my timelapse code?

This topic is 4197 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

I'm trying to get the time lapse aka delta time between loops, to move an object by that x value. Right now I'm doing:
while(1 == 1) {
    lastTime = time;
    time = System.nanoTime();

    //supposed to move 5 pixels a second
    x+=5.0f*(float)(time-LastTime);
}




Except I'm getting some huge number instead, what am I doing wrong? thx

Share this post


Link to post
Share on other sites
Advertisement
I assume System.nanoTime() returns the time in nanoseconds, your code will move 5 pixels per nanosecond. You need to divide by 10^-9 to convert to seconds.

In addition, check that 'time' has a reasonable value before the loop starts (probably the current time). It may contain invalid data depending on where and when it is declared.

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!