Skip to main content

FlixelGoalTween

View source

class

org.flixelgdx.tween.type.FlixelGoalTween

public class FlixelGoalTween extends FlixelTween

Tween type for animating any object via lambda getters and setters.

It's intended to be used the following way:

// Use the FlixelTween class to use this type.
FlixelTween.tween(myObject, new FlixelTweenSettings()
.addGoal(myObject::getFoo, 100f, myObject::setFoo)
.addGoal(myObject::getBar, 200f, myObject::setBar));

If you need to cancel a specific tween of an object, you can add a label to the tween via FlixelGoalTween.setFieldLabel(String) and use that label in your game's code to cancel or complete that tween:

FlixelGoalTween t = (FlixelGoalTween) FlixelTween.tween(myObject, new FlixelTweenSettings()
.addGoal(myObject::getFoo, 100f, myObject::setFoo)
.addGoal(myObject::getBar, 200f, myObject::setBar));

t.setFieldLabel("yourLabel");

// Later in your game's code...
FlixelTween.cancelTweensOf(myObject, "yourLabel");
FlixelTween.completeTweensOf(myObject, "yourLabel");

See Also: FlixelTweenSettings

Constructors

FlixelGoalTween(FlixelTweenSettings)

public FlixelGoalTween(FlixelTweenSettings settings)

Constructs a new goal tween with the given settings. Goals must be added via FlixelTweenSettings.addGoal(...) before starting.

Parameters:

NameDescription
settingsThe settings that configure and determine how the tween should animate.

Fields

tweenObject

protected Object tweenObject

Logical subject for FlixelGoalTween.isTweenOf(Object, String); must be set before FlixelGoalTween.start() / FlixelTweenManager.addTween(FlixelTween).


fieldLabel

protected String fieldLabel

Optional label for FlixelGoalTween.isTweenOf(Object, String) when no intrinsic property name exists.


cachedPropertyGoals

protected Array<FlixelTweenGoal> cachedPropertyGoals

Cached property goals captured at FlixelGoalTween.start() to avoid re-allocating the list every frame inside FlixelGoalTween.updateTweenValues().


propertyGoalStartValues

protected FloatArray propertyGoalStartValues

Initial values of each property goal, captured from their getter at FlixelGoalTween.start(), indexed parallel to FlixelGoalTween.cachedPropertyGoals.


Methods

setObject(Object)

public FlixelGoalTween setObject(Object tweenObject)

Sets the object this tween logically animates (required before FlixelGoalTween.start()).

This has to be set because FlixelGoalTween.isTweenOf(Object, String) needs to know the object to tween. This method is purely for logic purposes used by FlixelTweenManager, not for tweening purposes.

Parameters:

NameDescription
tweenObjectThe object to tween.

Returns: this for chaining.


setFieldLabel(String)

public FlixelGoalTween setFieldLabel(String fieldLabel)

Assigns an optional logical field name used by FlixelGoalTween.isTweenOf(Object, String) when checking whether this tween animates a particular named property.

Parameters:

NameDescription
fieldLabelThe field label to associate with this tween, or null to clear any previously set label.

Returns: This tween instance for method chaining.


getTweenObject()

public Object getTweenObject()

Returns the logical target object that this tween animates, or null if no object has been set yet.

Returns: The tween target object, or null.


getFieldLabel()

public String getFieldLabel()

Returns the optional logical field label associated with this tween, or null if none has been set.

Returns: The field label, or null.


start()

public FlixelTween start()

updateTweenValues()

protected void updateTweenValues()

restart()

public void restart()

reset()

public void reset()

isTweenOf(Object, String)

public boolean isTweenOf(Object o, String field)

Returns whether this tween matches the given object and optional field path.

When field contains no '.', the match requires object identity with FlixelGoalTween.setObject(Object) and, if FlixelGoalTween.setFieldLabel(String) was used, equality between field and that label.

When field is dotted, the framework no longer walks nested objects. Matching succeeds only when o is the same instance as the logical tween object and the segment after the final '.' equals fieldLabel when a label is configured (or any suffix when the label is null). Callers that cancel tweens using a root object and a long dotted path should pass the same object reference that was passed to setObject(...).

Parameters:

NameDescription
oCandidate object from the manager query.
fieldOptional path string (may contain dots).

Returns: true when this tween should be treated as a match.