Advertisement Jump to content
Sign in to follow this  

Java whats wrong with my timelapse code?

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

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

Share this post

Link to post
Share on other sites
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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!