Package nl.colorize.multimedialib.scene
Class Timer
java.lang.Object
nl.colorize.multimedialib.scene.Timer
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionTimer(float duration) Creates a new timer with the specified duration in seconds. -
Method Summary
Modifier and TypeMethodDescriptionstatic Timerat(float time) Factory method that creates a timer which has its position set to the specified value.static Timerat(float time, float duration) Factory method that creates a timer with the specified duration, which has its position set to the specified value.voidend()static Timerended(float duration) Factory method that creates a timer which starts in the completed state, with the playhead set to the timer's duration.floatfloatfloatgetRatio()floatgetTime()floatstatic Timerinfinite()Factory method that creates a timer which will never reach his duration, meaning the timer will never be marked as completed.booleanstatic Timernone()Factory method that creates a timer with a zero duration.voidreset()voidsetTime(float time) toString()voidupdate(float deltaTime) Updates this object for the current frame.
-
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:UpdatableUpdates this object for the current frame.deltaTimeindicates the elapsed time since the last frame update, in seconds. -
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
-
at
Factory method that creates a timer with the specified duration, which has its position set to the specified value. -
at
Factory method that creates a timer which has its position set to the specified value. The timer will never reach its duration, similar toinfinite(). -
none
Factory method that creates a timer with a zero duration. This will immediately mark the timer as completed upon creation. -
infinite
Factory method that creates a timer which will never reach his duration, meaning the timer will never be marked as completed. -
ended
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()
-