FlixelTimer
View sourceclass
org.flixelgdx.util.timer.FlixelTimer
Frame-based countdown timer.
Advance time by calling FlixelTimerManager.update(float) once per frame (done automatically for FlixelTimer.getGlobalManager()). The elapsed argument should already include Flixel.timeScale.
Prefer FlixelTimerManager.start(...), FlixelTimer.wait(float, FlixelTimerListener), or FlixelTimer.loop(...) so pooled instances are reused.
The callback runs on the next update (one frame later), loops is ignored.
The timer is removed from its manager before the final callback runs.
Constructors
FlixelTimer()
Constructs a new timer object with the global manager.
FlixelTimer(FlixelTimerManager)
Constructs a new timer object with a parent manager.
Parameters:
| Name | Description |
|---|---|
manager | The parent manager of the timer. |
Fields
time
The time to complete the timer.
loops
Requested loop count. 0 means infinite (only when FlixelTimer.time is greater than zero).
elapsedLoops
The number of loops the timer has completed.
elapsedTime
The time elapsed since the timer started.
onComplete
The callback to run when the timer completes.
manager
The parent manager of the timer.
active
Whether the timer is currently active.
finished
Whether the timer has finished.
Methods
getTimeLeft()
getLoopsLeft()
getProgress()
start(float, FlixelTimerListener)
Starts the timer.
Parameters:
| Name | Description |
|---|---|
timeSeconds | The time to complete the timer. |
onComplete | The callback to run when the timer completes. |
Returns: The timer.
start(float, FlixelTimerListener, int)
Restarts this timer on its current FlixelTimer.manager without allocating a new instance.
Parameters:
| Name | Description |
|---|---|
timeSeconds | The time to complete the timer. |
onComplete | The callback to run when the timer completes. |
loopCount | The number of loops to run the timer. |
Returns: The timer.
restart(float)
Restarts the timer.
Parameters:
| Name | Description |
|---|---|
newTimeSeconds | The new time to complete the timer. |
Returns: The timer.
cancel()
Cancels the timer and removes it from its manager.
markFinished()
Marks the timer as finished.
update(float)
destroy()
reset()
cancelAll()
Cancels all active timers in the global manager.
completeAll()
Completes all active timers in the global manager.
wait(float, FlixelTimerListener)
Starts a pooled timer registered with the global manager.
Parameters:
| Name | Description |
|---|---|
timeSeconds | The time to complete the timer. |
onComplete | The callback to run when the timer completes. |
Returns: The timer.
loop(float, FlixelTimerListener, int)
Starts a pooled timer registered with the global manager.
Parameters:
| Name | Description |
|---|---|
timeSeconds | The time to complete the timer. |
onEachLoop | The callback to run when the timer completes each loop. |
loopCount | The number of loops to run the timer. |
Returns: The timer.