FlixelTweenManager
View sourceclass
org.flixelgdx.tween.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()
Fields
activeTweens
Active tweens; unordered so FlixelTweenManager.removeTween(FlixelTween, boolean) is O(1) without snapshot copies.
Methods
registerTweenType(Class<T>, Supplier<T>)
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:
| Name | Description |
|---|---|
tweenClass | The tween class (e.g. FlixelGoalTween.class). |
poolFactory | A supplier that creates a new tween instance when the pool is empty. |
Returns: The same manager, for chaining.
Throws:
| Type | Description |
|---|---|
IllegalArgumentException | if the tween type is already registered. |
addTween(FlixelTween)
Adds the tween to this manager and starts it immediately.
Parameters:
| Name | Description |
|---|---|
tween | The tween to add and start. |
Returns: The same tween, for chaining.
update(float)
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:
| Name | Description |
|---|---|
elapsed | The amount of time that has passed since the last frame. |
obtainTween(Class<T>, Supplier<T>)
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:
| Name | Description |
|---|---|
type | The tween class (e.g. FlixelGoalTween.class). |
factory | Fallback 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)
Remove an FlixelTween from this manager. When destroy is true, the tween is reset and returned to its type's pool if registered.
Parameters:
| Name | Description |
|---|---|
tween | The tween to remove. |
destroy | If true, reset the tween and free it to the pool (if its type is registered). |
Returns: The removed tween.
getPool(Class<? extends FlixelTween>)
clearPools()
getActiveTweens()
cancelTweensOf(Object, String...)
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:
| Name | Description |
|---|---|
object | Non-null root instance (same as passed to FlixelTween.isTweenOf(Object, String)). |
fieldPaths | Optional goal keys or dotted paths; empty means match all fields on object. |
completeTweensOf(Object, String...)
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:
| Name | Description |
|---|---|
object | The object to complete tweens of. |
fieldPaths | The field paths to complete tweens of. |
Throws:
| Type | Description |
|---|---|
NullPointerException | If the object is null. |
IllegalArgumentException | If the object is null. |
completeAll()
Completes all active non-looping tweens.
completeTweensOfType(Class<? extends FlixelTween>)
Completes all active tweens assignable to type (non-looping only).
Parameters:
| Name | Description |
|---|---|
type | The type of tween to complete. |
Throws:
| Type | Description |
|---|---|
NullPointerException | If the type is null. |
IllegalArgumentException | If the type is null. |
containsTweensOf(Object, String...)
Returns whether any active tween matches object and optional fieldPaths (OR).
Parameters:
| Name | Description |
|---|---|
object | The object to check for tweens of. |
fieldPaths | The field paths to check for tweens of. |
Returns: True if the manager contains tweens of the given object and field paths, false otherwise.
Throws:
| Type | Description |
|---|---|
NullPointerException | If the object is null. |
IllegalArgumentException | If the object is null. |
forEach(Consumer<FlixelTween>)
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:
| Name | Description |
|---|---|
action | The action to invoke for each active tween. |
Throws:
| Type | Description |
|---|---|
NullPointerException | If the action is null. |
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
Registry entry for a tween type: the object pool used for tween reuse.
Constructors
TweenTypeRegistration(Pool<FlixelTween>)
Parameters:
| Name | Description |
|---|---|
pool | The object pool for recycling tween instances. |