Skip to main content

FlixelTimer

View source

class

org.flixelgdx.util.timer.FlixelTimer

public class FlixelTimer implements FlixelUpdatable, FlixelDestroyable, Poolable

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()

public FlixelTimer()

Constructs a new timer object with the global manager.


FlixelTimer(FlixelTimerManager)

public FlixelTimer(FlixelTimerManager manager)

Constructs a new timer object with a parent manager.

Parameters:

NameDescription
managerThe parent manager of the timer.

Fields

time

public float time

The time to complete the timer.


loops

public int loops

Requested loop count. 0 means infinite (only when FlixelTimer.time is greater than zero).


elapsedLoops

public int elapsedLoops

The number of loops the timer has completed.


elapsedTime

public float elapsedTime

The time elapsed since the timer started.


onComplete

public FlixelTimerListener onComplete

The callback to run when the timer completes.


manager

protected FlixelTimerManager manager

The parent manager of the timer.


active

public boolean active

Whether the timer is currently active.


finished

public boolean finished

Whether the timer has finished.


Methods

getTimeLeft()

public float getTimeLeft()

getLoopsLeft()

public int getLoopsLeft()

getProgress()

public float getProgress()

start(float, FlixelTimerListener)

public FlixelTimer start(float timeSeconds, FlixelTimerListener onComplete)

Starts the timer.

Parameters:

NameDescription
timeSecondsThe time to complete the timer.
onCompleteThe callback to run when the timer completes.

Returns: The timer.


start(float, FlixelTimerListener, int)

public FlixelTimer start(float timeSeconds, FlixelTimerListener onComplete, int loopCount)

Restarts this timer on its current FlixelTimer.manager without allocating a new instance.

Parameters:

NameDescription
timeSecondsThe time to complete the timer.
onCompleteThe callback to run when the timer completes.
loopCountThe number of loops to run the timer.

Returns: The timer.


restart(float)

public FlixelTimer restart(float newTimeSeconds)

Restarts the timer.

Parameters:

NameDescription
newTimeSecondsThe new time to complete the timer.

Returns: The timer.


cancel()

public void cancel()

Cancels the timer and removes it from its manager.


markFinished()

public void markFinished()

Marks the timer as finished.


update(float)

public void update(float elapsed)

destroy()

public void destroy()

reset()

public void reset()

cancelAll()

public static void cancelAll()

Cancels all active timers in the global manager.


completeAll()

public static void completeAll()

Completes all active timers in the global manager.


wait(float, FlixelTimerListener)

public static FlixelTimer wait(float timeSeconds, FlixelTimerListener onComplete)

Starts a pooled timer registered with the global manager.

Parameters:

NameDescription
timeSecondsThe time to complete the timer.
onCompleteThe callback to run when the timer completes.

Returns: The timer.


loop(float, FlixelTimerListener, int)

public static FlixelTimer loop(float timeSeconds, FlixelTimerListener onEachLoop, int loopCount)

Starts a pooled timer registered with the global manager.

Parameters:

NameDescription
timeSecondsThe time to complete the timer.
onEachLoopThe callback to run when the timer completes each loop.
loopCountThe number of loops to run the timer.

Returns: The timer.


getGlobalManager()

public static FlixelTimerManager getGlobalManager()