LWJGL Timer

The LWJGL org.lwjgl.util.Timer provides a simple wrapper around the Timer/Ticks timing mechanism provided by the Sys class. Its intention it to provide a away of accessing accurate system timing in seconds.

Usage

The standard usage is to create a Timer instance locally to where you require timing and then call getTime(). For instance, it may be useful as part of an animation handling routine to have a local timer.

public void init() {
    Timer animTimer = new Timer();
}
 
public void udpate() {
    float delta = animTimer.getTime() - lastTime;
    lastTime = animTimer.getTime();
 
    // update the animation by delta seconds
}

However, to make this work you must remember to call the static method on Timer each game loop:

public void gameLoop() {
      Timer.tick();
 
      // .. other logic/rendering here ..
}

Now, what if you wanted the animation to pause for a moment while you display a menu? Since we've got a local timer we can simply call:

     animTimer.pause();

and then once the menu has been removed:

     animTimer.resume();

to start the timer again.

 
lwjgl/tutorials/usingtimer.txt · Last modified: 2007/07/07 00:38 (external edit)
 
Recent changes RSS feed Creative Commons License Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki