Skip to main content

FlixelTimerManager

View source

class

org.flixelgdx.util.timer.FlixelTimerManager

public class FlixelTimerManager extends FlixelBasic

Owns active FlixelTimer instances and advances them once per frame. Extends FlixelBasic like HaxeFlixel plugin-style managers so FlixelTimerManager.active, FlixelTimerManager.exists, FlixelTimerManager.kill, and FlixelTimerManager.destroy() gate FlixelTimerManager.update(float) the same way as other Flixel objects.

Use FlixelTimer.getGlobalManager() with FlixelGame (already wired) or construct a dedicated manager for isolated groups (for example add it to a FlixelState).

Timers are backed by a Pool to avoid per-delay allocations. FlixelTimerManager.start(...) obtains from the pool; FlixelTimer.cancel() and completed runs return instances to the pool.

Constructors

FlixelTimerManager()

public FlixelTimerManager()

Creates a new timer manager with a default pool of capacity 32.


Fields

activeTimers

protected final Array<FlixelTimer> activeTimers

Timers currently stepped by FlixelTimerManager.update(float). Named activeTimers to avoid clashing with FlixelTimerManager.active.


pool

protected final Pool<FlixelTimer> pool

Methods

start(float, FlixelTimerListener, int)

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

Starts a pooled timer registered with this manager.

Parameters:

NameDescription
timeSecondsSee the documentation for FlixelTimer.start(...).
onCompleteOptional callback (each loop, including the last).
loopCount0 for infinite.

Returns: The started timer.


start(float, FlixelTimerListener)

public FlixelTimer start(float timeSeconds, FlixelTimerListener onComplete)

Starts a pooled timer registered with this manager.

Parameters:

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

Returns: The timer.


update(float)

public void update(float elapsed)

draw(FlixelBatch)

public final void draw(FlixelBatch batch)

destroy()

public void destroy()

addIfMissing(FlixelTimer)

public void addIfMissing(FlixelTimer t)

Adds a timer to the active list if it is not already present.

Parameters:

NameDescription
tThe timer to add.

detachOnly(FlixelTimer)

public void detachOnly(FlixelTimer t)

Removes the timer from the active list without returning it to the pool (used before restart).

Parameters:

NameDescription
tThe timer to remove.

removeAndFree(FlixelTimer)

public void removeAndFree(FlixelTimer t)

Removes the timer from the active list and frees it from the pool.

Parameters:

NameDescription
tThe timer to remove.

finishLast(FlixelTimer, FlixelTimerListener)

public void finishLast(FlixelTimer t, FlixelTimerListener cb)

Removes the timer from the active list, invokes the listener, then returns the instance to the pool. Used for the final iteration so the callback sees a finished timer that is no longer managed.

Parameters:

NameDescription
tThe timer to finish.
cbThe callback to run when the timer finishes.

cancelAll()

public void cancelAll()

Stops every running timer and returns instances to the pool.


completeAll()

public void completeAll()

Completes all active timers in the manager.