Package org.xjge.core

Class StopWatch

java.lang.Object
org.xjge.core.StopWatch

public class StopWatch
extends java.lang.Object
Provides a simple timing mechanism that exhibits greater accuracy than Game.tick(int) alone by capturing the timestamp of the initial game tick from which tick(int,int,boolean) was called and comparing it to subsequent ticks until the specified number of cycles have passed.
Since:
2.0.0
  • Constructor Summary

    Constructors
    Constructor Description
    StopWatch()  
  • Method Summary

    Modifier and Type Method Description
    int getTime()
    Obtains the current value of the time field.
    boolean tick​(int speed)
    Simplified version of tick(int,int,boolean) that mimics the functionality of the Game.tick(int) method but with improved accuracy.
    boolean tick​(int time, int speed, boolean increment)
    Returns true anytime the specified number of update iterations (or cycles) have been reached following the current game tick this method was initially called at.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StopWatch

      public StopWatch()
  • Method Details

    • tick

      public boolean tick​(int speed)
      Simplified version of tick(int,int,boolean) that mimics the functionality of the Game.tick(int) method but with improved accuracy.
      Parameters:
      speed - the number of game ticks to wait before changing the time value. A single tick typically takes 16 milliseconds.
      Returns:
      true every time the specified number of cycles has been reached
    • tick

      public boolean tick​(int time, int speed, boolean increment)
      Returns true anytime the specified number of update iterations (or cycles) have been reached following the current game tick this method was initially called at.

      The number of ticks (provided through getTime()) will reset upon reaching the value specified in the time argument. However, if false is passed to the increment argument, it will instead reset upon reaching zero.

      NOTE: The value of time is zero-inclusive. As such, passing a value of five (counting down) will actually start at four, and reset after zero has been reached. This method will always return true on the first call.

      Parameters:
      time - the total number of intervals the timer must complete before it restarts
      speed - the number of game ticks to wait before changing the time value. A single tick typically takes 16 milliseconds.
      increment - if true, the stopwatch will count upwards. Otherwise it will count down.
      Returns:
      true every time the specified number of cycles has been reached
    • getTime

      public int getTime()
      Obtains the current value of the time field.
      Returns:
      the current time the stopwatch is at