Class Timer

java.lang.Object
nl.colorize.multimedialib.scene.Timer
All Implemented Interfaces:
Updatable

public class Timer extends Object implements Updatable
Utility class for time-based behavior. A timer consists of a position and a duration. The position is moved during every frame update, until the duration has been reached.

The timer is based on float precision, meaning the timer can run for about 2.5-3 hours before float precision errors start to occur.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Timer(float duration)
    Creates a new timer with the specified duration in seconds.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Timer
    at(float time)
    Factory method that creates a timer which has its position set to the specified value.
    static Timer
    at(float time, float duration)
    Factory method that creates a timer with the specified duration, which has its position set to the specified value.
    void
    end()
     
    static Timer
    ended(float duration)
    Factory method that creates a timer which starts in the completed state, with the playhead set to the timer's duration.
    float
     
    float
     
    float
     
    float
     
    float
     
    static Timer
    Factory method that creates a timer which will never reach his duration, meaning the timer will never be marked as completed.
    boolean
     
    static Timer
    Factory method that creates a timer with a zero duration.
    void
     
    void
    setTime(float time)
     
     
    void
    update(float deltaTime)
    Updates this object for the current frame.

    Methods inherited from class java.lang.Object

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

    • Timer

      public Timer(float duration)
      Creates a new timer with the specified duration in seconds. A duration of zero is allowed, and indicates the timer will immmediately be considered as completed upon creation.
      Throws:
      IllegalArgumentException - for a negative timer duration.
  • Method Details

    • update

      public void update(float deltaTime)
      Description copied from interface: Updatable
      Updates this object for the current frame. deltaTime indicates the elapsed time since the last frame update, in seconds.
      Specified by:
      update in interface Updatable
    • setTime

      public void setTime(float time)
    • getTime

      public float getTime()
    • getTimeRemaining

      public float getTimeRemaining()
    • isCompleted

      public boolean isCompleted()
    • getRatio

      public float getRatio()
    • reset

      public void reset()
    • end

      public void end()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • at

      public static Timer at(float time, float duration)
      Factory method that creates a timer with the specified duration, which has its position set to the specified value.
    • at

      public static Timer at(float time)
      Factory method that creates a timer which has its position set to the specified value. The timer will never reach its duration, similar to infinite().
    • none

      public static Timer none()
      Factory method that creates a timer with a zero duration. This will immediately mark the timer as completed upon creation.
    • infinite

      public static Timer infinite()
      Factory method that creates a timer which will never reach his duration, meaning the timer will never be marked as completed.
    • ended

      public static Timer ended(float duration)
      Factory method that creates a timer which starts in the completed state, with the playhead set to the timer's duration.
    • getPosition

      public float getPosition()
    • getDuration

      public float getDuration()