Skip to main content

FlixelTweenManager

View source

class

org.flixelgdx.tween.FlixelTweenManager

public class FlixelTweenManager

Manager class for handling a list of active FlixelTweens.

Normally used via FlixelTween.getGlobalManager() or the static helpers on FlixelTween (e.g. FlixelTween.updateTweens(float), FlixelTween.registerTweenType(Class<T>, Supplier<T>)) rather than instantiating separately. Adding a tween via FlixelTweenManager.addTween(FlixelTween) automatically starts it.

Uses a registry: each tween type is registered with a pool factory. Registered types can be obtained via FlixelTweenManager.obtainTween(Class<T>, Supplier<T>). Call FlixelTweenManager.clearPools() when clearing state (e.g. on state switch) to release pooled instances.

Active tweens use an unordered Array: removals swap with the last element (no SnapshotArray copy-on-write), so the per-frame update path stays allocation-free even when tweens finish and unregister.

Constructors

FlixelTweenManager()

public FlixelTweenManager()

Fields

activeTweens

protected final Array<FlixelTween> activeTweens

Active tweens; unordered so FlixelTweenManager.removeTween(FlixelTween, boolean) is O(1) without snapshot copies.


Methods

registerTweenType(Class<T>, Supplier<T>)

public FlixelTweenManager registerTweenType(Class<T> tweenClass, Supplier<T> poolFactory)

Registers a tween type with a pool factory for creating new tween instances when the pool is empty. Register all tween types (including custom ones) before using FlixelTweenManager.obtainTween(Class<T>, Supplier<T>) with that tween class.

Parameters:

NameDescription
tweenClassThe tween class (e.g. FlixelGoalTween.class).
poolFactoryA supplier that creates a new tween instance when the pool is empty.

Returns: The same manager, for chaining.

Throws:

TypeDescription
IllegalArgumentExceptionif the tween type is already registered.

addTween(FlixelTween)

public FlixelTween addTween(FlixelTween tween)

Adds the tween to this manager and starts it immediately.

Parameters:

NameDescription
tweenThe tween to add and start.

Returns: The same tween, for chaining.


update(float)

public void update(float elapsed)

Updates all active tweens that are stored and updated in this manager.

The finish pass runs in reverse order so FlixelTween.finish() can remove tweens (swap-with-last removal) without skipping entries.

Parameters:

NameDescription
elapsedThe amount of time that has passed since the last frame.

obtainTween(Class<T>, Supplier<T>)

public T obtainTween(Class<T> type, Supplier<T> factory)

Obtains a tween of the given type from the registry's pool. The returned instance is reset; the caller must set FlixelTween.setTweenSettings(FlixelTweenSettings) and any type-specific state (for example FlixelGoalTween.setObject(Object)) before FlixelTweenManager.addTween(FlixelTween). The factory is only used when the type is not registered; registered types ignore the supplier and use the pool's newObject() method.

Parameters:

NameDescription
typeThe tween class (e.g. FlixelGoalTween.class).
factoryFallback factory when the type is not registered or the pool is empty.

Returns: A reset tween of type T, either from the pool or from factory.


removeTween(FlixelTween, boolean)

public FlixelTween removeTween(FlixelTween tween, boolean destroy)

Remove an FlixelTween from this manager. When destroy is true, the tween is reset and returned to its type's pool if registered.

Parameters:

NameDescription
tweenThe tween to remove.
destroyIf true, reset the tween and free it to the pool (if its type is registered).

Returns: The removed tween.


getPool(Class<? extends FlixelTween>)

public Pool<FlixelTween> getPool(Class<? extends FlixelTween> tweenClass)

clearPools()

public void clearPools()

getActiveTweens()

public Array<FlixelTween> getActiveTweens()

cancelTweensOf(Object, String...)

public void cancelTweensOf(Object object, String... fieldPaths)

Cancels all active tweens matching object and optional field paths (OR semantics). When fieldPaths is empty, matches any tween FlixelTween.isTweenOf(Object, String) on object with a null/empty field.

Parameters:

NameDescription
objectNon-null root instance (same as passed to FlixelTween.isTweenOf(Object, String)).
fieldPathsOptional goal keys or dotted paths; empty means match all fields on object.

completeTweensOf(Object, String...)

public void completeTweensOf(Object object, String... fieldPaths)

Completes matching tweens in one step (large delta). Non-looping tweens only. FlixelTweenSettings.getOnComplete() runs when FlixelTween.finish() is invoked after the tween reports finished.

Parameters:

NameDescription
objectThe object to complete tweens of.
fieldPathsThe field paths to complete tweens of.

Throws:

TypeDescription
NullPointerExceptionIf the object is null.
IllegalArgumentExceptionIf the object is null.

completeAll()

public void completeAll()

Completes all active non-looping tweens.


completeTweensOfType(Class<? extends FlixelTween>)

public void completeTweensOfType(Class<? extends FlixelTween> type)

Completes all active tweens assignable to type (non-looping only).

Parameters:

NameDescription
typeThe type of tween to complete.

Throws:

TypeDescription
NullPointerExceptionIf the type is null.
IllegalArgumentExceptionIf the type is null.

containsTweensOf(Object, String...)

public boolean containsTweensOf(Object object, String... fieldPaths)

Returns whether any active tween matches object and optional fieldPaths (OR).

Parameters:

NameDescription
objectThe object to check for tweens of.
fieldPathsThe field paths to check for tweens of.

Returns: True if the manager contains tweens of the given object and field paths, false otherwise.

Throws:

TypeDescription
NullPointerExceptionIf the object is null.
IllegalArgumentExceptionIf the object is null.

forEach(Consumer<FlixelTween>)

public void forEach(Consumer<FlixelTween> action)

Invokes action for each active tween. Iteration is from the end of the backing array downward so action may cancel or remove tweens without skipping entries.

Parameters:

NameDescription
actionThe action to invoke for each active tween.

Throws:

TypeDescription
NullPointerExceptionIf the action is null.

resetRegistry()

public void resetRegistry()

Clears the registry of all registered tween types and their respective pools.

It is advised to only call this if you know what you are doing, as this will include the default registered tween types. If you call this, you will need to register the tween types again.


TweenTypeRegistration

record

org.flixelgdx.tween.FlixelTweenManager.TweenTypeRegistration

public static final record TweenTypeRegistration(Pool<FlixelTween> pool)

Registry entry for a tween type: the object pool used for tween reuse.

Constructors

TweenTypeRegistration(Pool<FlixelTween>)

public TweenTypeRegistration(Pool<FlixelTween> pool)

Parameters:

NameDescription
poolThe object pool for recycling tween instances.

Methods

toString()

public final String toString()

hashCode()

public final int hashCode()

equals(Object)

public final boolean equals(Object o)

pool()

public Pool<FlixelTween> pool()