Node useful for animations with unknown start and end points.
    public class Tween : Node

Node useful for animations with unknown start and end points, procedural animations, making one node follow another, and other simple behavior.

Because it is easy to get it wrong, here is a quick usage example:

[codeblock]

var tween = get_node(“Tween”)

tween.interpolate_property(get_node(“Node2D_to_move”), “transform/origin”, Vector2(0,0), Vector2(100,100), 1, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)

tween.start()

[/codeblock]

Some of the methods of this class require a property name. You can get the property name by hovering over the property in the inspector of the editor.

Many of the methods accept trans_type and ease_type. The first accepts an TRANS_* constant, and refers to the way the timing of the animation is handled (you might want to see http://easings.net/ for some examples). The second accepts an EASE_* constant, and controls the where trans_type is applied to the interpolation (in the beginning, the end, or both). If you don’t know which transition and easing to pick, you can try different TRANS_* constants with EASE_IN_OUT, and use the one that looks best.

Inheritance Chain

Constructors

    public Tween()

Signals

    "tween_completed" (Object object, NodePath key)

This signal is emitted when a tween ends.

    "tween_started" (Object object, NodePath key)

This signal is emitted when a tween starts.

    "tween_step" (Object object, NodePath key, float elapsed, Object value)

This signal is emitted each step of the tweening.

Properties

    public TweenProcessMode PlaybackProcessMode { get; set; }

    public float PlaybackSpeed { get; set; }

The speed multiplier of the tween. Set it to 1 for normal speed, 2 for two times nromal speed, and 0.5 for half of the normal speed. Setting it to 0 would pause the animation, but you might consider using SetActive(bool) or StopAll() and ResumeAll() for this.

    public bool Repeat { get; set; }

If true, the tween will repeat.

Methods

    public bool FollowMethod(Object @object, string method, object initialVal, Object target, string targetMethod, float duration, TransitionType transType, EaseType easeType, float delay = 0f)

Follow method of object and apply the returned value on targetMethod of target, beginning from initialVal for duration seconds, delay later. Methods are animated by calling them with consequitive values.

transType accepts TRANS_* constants, and is the way the animation is interpolated, while easeType accepts EASE_* constants, and controls the place of the interpolation (the beginning, the end, or both). You can read more about them in the class description.

    public bool FollowProperty(Object @object, NodePath property, object initialVal, Object target, NodePath targetProperty, float duration, TransitionType transType, EaseType easeType, float delay = 0f)

Follow property of object and apply it on targetProperty of target, beginning from initialVal for duration seconds, delay seconds later. Note that target:target_property would equal object:property at the end of the tween.

transType accepts TRANS_* constants, and is the way the animation is interpolated, while easeType accepts EASE_* constants, and controls the place of the interpolation (the beginning, the end, or both). You can read more about them in the class description.

    public float GetRuntime()

Returns the time needed for all tweens to end in seconds, measured from the start. Thus, if you have two tweens, one ending 10 seconds after the start and the other - 20 seconds, it would return 20 seconds, as by that time all tweens would have finished.

    public float GetSpeedScale()

Getter for PlaybackSpeed

    public TweenProcessMode GetTweenProcessMode()

Getter for PlaybackProcessMode

    public bool InterpolateCallback(Object @object, float duration, string callback, object arg1 = null, object arg2 = null, object arg3 = null, object arg4 = null, object arg5 = null)

Call callback of object after duration. arg1-arg5 are arguments to be passed to the callback.

    public bool InterpolateDeferredCallback(Object @object, float duration, string callback, object arg1 = null, object arg2 = null, object arg3 = null, object arg4 = null, object arg5 = null)

Call callback of object after duration on the main thread (similar to Object.CallDeferred(string, params object[])). arg1-arg5 are arguments to be passed to the callback.

    public bool InterpolateMethod(Object @object, string method, object initialVal, object finalVal, float duration, TransitionType transType, EaseType easeType, float delay = 0f)

Animate method of object from initialVal to finalVal for duration seconds, delay seconds later. Methods are animated by calling them with consecutive values.

transType accepts TRANS_* constants, and is the way the animation is interpolated, while easeType accepts EASE_* constants, and controls the place of the interpolation (the beginning, the end, or both). You can read more about them in the class description.

    public bool InterpolateProperty(Object @object, NodePath property, object initialVal, object finalVal, float duration, TransitionType transType, EaseType easeType, float delay = 0f)

Animate property of object from initialVal to finalVal for duration seconds, delay seconds later.

transType accepts TRANS_* constants, and is the way the animation is interpolated, while easeType accepts EASE_* constants, and controls the place of the interpolation (the beginning, the end, or both). You can read more about them in the class description.

    public bool IsActive()

Returns true if any tweens are currently running, and false otherwise. Note that this method doesn’t consider tweens that have ended.

    public bool IsRepeat()

Getter for Repeat

    public bool Remove(Object @object, string key = "")

Stop animating and completely remove a tween, given its object and property/method pair. Passing empty String as key will remove all tweens for given object.

    public bool RemoveAll()

Stop animating and completely remove all tweens.

    public bool Reset(Object @object, string key = "")

Resets a tween to the initial value (the one given, not the one before the tween), given its object and property/method pair. Passing empty String as key will reset all tweens for given object.

    public bool ResetAll()

Resets all tweens to their initial values (the ones given, not those before the tween).

    public bool Resume(Object @object, string key = "")

Continue animating a stopped tween, given its object and property/method pair. Passing empty String as key will resume all tweens for given object.

    public bool ResumeAll()

Continue animating all stopped tweens.

    public bool Seek(float time)

Seek the animation to the given time in seconds.

    public void SetActive(bool active)

Activate/deactivate the tween. You can use this for pausing animations, though StopAll() and ResumeAll() might be more fit for this.

    public void SetRepeat(bool repeat)

Setter for Repeat

    public void SetSpeedScale(float speed)

Setter for PlaybackSpeed

    public void SetTweenProcessMode(TweenProcessMode mode)

Setter for PlaybackProcessMode

    public bool Start()

Start the tween node. You can define tweens both before and after this.

    public bool Stop(Object @object, string key = "")

Stop animating a tween, given its object and property/method pair. Passing empty String as key will stop all tweens for given object.

    public bool StopAll()

Stop animating all tweens.

    public bool TargetingMethod(Object @object, string method, Object initial, string initialMethod, object finalVal, float duration, TransitionType transType, EaseType easeType, float delay = 0f)

Animate method of object from the value returned by initial.initial_method to finalVal for duration seconds, delay seconds later. Methods are animated by calling them with consecutive values.

transType accepts TRANS_* constants, and is the way the animation is interpolated, while easeType accepts EASE_* constants, and controls the place of the interpolation (the beginning, the end, or both). You can read more about them in the class description.

    public bool TargetingProperty(Object @object, NodePath property, Object initial, NodePath initialVal, object finalVal, float duration, TransitionType transType, EaseType easeType, float delay = 0f)

Animate property of object from the current value of the initialVal property of initial to finalVal for duration seconds, delay seconds later.

transType accepts TRANS_* constants, and is the way the animation is interpolated, while easeType accepts EASE_* constants, and controls the place of the interpolation (the beginning, the end, or both). You can read more about them in the class description.

    public float Tell()

Returns the current time of the tween.

Inner Types

EaseType

Name Value Description
In 0 Signifies that the interpolation should be focused in the beginning.
Out 1 Signifies that the interpolation should be focused in the end.
InOut 2 Signifies that the interpolation should be focused in both ends.
OutIn 3 Signifies that the interpolation should be focused in both ends, but they should be switched (a bit hard to explain, try it for yourself to be sure).

TransitionType

Name Value Description
Linear 0 Means that the animation is interpolated linearly.
Sine 1 Means that the animation is interpolated using a sine wave.
Quint 2 Means that the animation is interpolated with a quinary (to the power of 5) function.
Quart 3 Means that the animation is interpolated with a quartic (to the power of 4) function.
Quad 4 Means that the animation is interpolated with a quadratic (to the power of 2) function.
Expo 5 Means that the animation is interpolated with an exponential (some number to the power of x) function.
Elastic 6 Means that the animation is interpolated with elasticity, wiggling around the edges.
Cubic 7 Means that the animation is interpolated with a cubic (to the power of 3) function.
Circ 8 Means that the animation is interpolated with a function using square roots.
Bounce 9 Means that the animation is interpolated by bouncing at, but never surpassing, the end.
Back 10 Means that the animation is interpolated backing out at edges.

TweenProcessMode

Name Value Description
Physics 0 The [code]Tween[/code] should use [code]_physics_process[/code] for timekeeping when this is enabled.
Idle 1 The [code]Tween[/code] should use [code]_process[/code] for timekeeping when this is enabled (default).
Tags: