Smoothly animates a node's properties over time.
    public class Tween : Node

Tweens are useful for animations requiring a numerical property to be interpolated over a range of values. The name tween comes from in-betweening, an animation technique where you specify keyframes and the computer interpolates the frames that appear between them.

Here is a brief usage example that causes a 2D node to move smoothly between two positions:

[codeblock]

var tween = get_node(“Tween”)

tween.interpolate_property($Node2D, “position”,

Vector2(0, 0), Vector2(100, 100), 1,

Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)

tween.start()

[/codeblock]

Many methods require a property name, such as “position” above. You can find the correct property name by hovering over the property in the Inspector. You can also provide the components of a property directly by using “property:component” (eg. position:x), where it would only apply to that particular component.

Many of the methods accept trans_type and ease_type. The first accepts an TransitionType constant, and refers to the way the timing of the animation is handled (see http://easings.net/ for some examples). The second accepts an EaseType 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 TransitionType constants with EASE_IN_OUT, and use the one that looks best.

Inheritance Chain

Constructors

    public Tween()

Signals

    "tween_completed" (Object object, NodePath key)

Emitted when a tween ends.

    "tween_started" (Object object, NodePath key)

Emitted when a tween starts.

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

Emitted at each step of the animation.

Properties

    public TweenProcessMode PlaybackProcessMode { get; set; }

The tween’s animation process thread. See TweenProcessMode. Default value: [constant TWEEN_PROCESS_IDLE].

    public float PlaybackSpeed { get; set; }

The tween’s speed multiplier. For example, set it to 1.0 for normal speed, 2.0 for two times normal speed, or 0.5 for half of the normal speed. A value of 0 pauses the animation, but see also SetActive(bool) or StopAll() for this.

    public bool Repeat { get; set; }

If true, the tween loops.

Methods

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

Follows method of object and applies the returned value on targetMethod of target, beginning from initialVal for duration seconds, delay later. Methods are called with consecutive values.

Use TransitionType for transType and EaseType for easeType parameters. These values control the timing and direction of the interpolation. See the class description for more information

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

Follows property of object and applies it on targetProperty of target, beginning from initialVal for duration seconds, delay seconds later.

Use TransitionType for transType and EaseType for easeType parameters. These values control the timing and direction of the interpolation. See the class description for more information

    public float GetRuntime()

Returns the total time needed for all tweens to end. If you have two tweens, one lasting 10 seconds 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)

Calls 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)

Calls 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)

Animates method of object from initialVal to finalVal for duration seconds, delay seconds later. Methods are called with consecutive values.

Use TransitionType for transType and EaseType for easeType parameters. These values control the timing and direction of the interpolation. See the class description for more information

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

Animates property of object from initialVal to finalVal for duration seconds, delay seconds later. Setting the initial value to null uses the current value of the property.

Use TransitionType for transType and EaseType for easeType parameters. These values control the timing and direction of the interpolation. See the class description for more information

    public bool IsActive()

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

    public bool IsRepeat()

Getter for Repeat

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

Stops animation and removes a tween, given its object and property/method pair. By default, all tweens are removed, unless key is specified.

    public bool RemoveAll()

Stops animation and removes all tweens.

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

Resets a tween to its initial value (the one given, not the one before the tween), given its object and property/method pair. By default, all tweens are removed, unless key is specified.

    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 = "")

Continues animating a stopped tween, given its object and property/method pair. By default, all tweens are resumed, unless key is specified.

    public bool ResumeAll()

Continues animating all stopped tweens.

    public bool Seek(float time)

Sets the interpolation to the given time in seconds.

    public void SetActive(bool active)

Activates/deactivates the tween. See also StopAll() and ResumeAll().

    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()

Starts the tween. You can define animations both before and after this.

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

Stops a tween, given its object and property/method pair. By default, all tweens are stopped, unless key is specified.

    public bool StopAll()

Stops 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)

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

Use TransitionType for transType and EaseType for easeType parameters. These values control the timing and direction of the interpolation. See the class description for more information

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

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

Use TransitionType for transType and EaseType for easeType parameters. These values control the timing and direction of the interpolation. See the class description for more information

    public float Tell()

Returns the current time of the tween.

Inner Types

EaseType

Name Value Description
In 0 The interpolation starts slowly and speeds up towards the end.
Out 1 The interpolation starts quickly and slows down towards the end.
InOut 2 A combination of EASE_IN and EASE_OUT. The interpolation is slowest at both ends.
OutIn 3 A combination of EASE_IN and EASE_OUT. The interpolation is fastest at both ends.

TransitionType

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

TweenProcessMode

Name Value Description
Physics 0 The tween updates with the [code]_physics_process[/code] callback.
Idle 1 The tween updates with the [code]_process[/code] callback.
Tags: