Tween¶
Smoothly animates a node's properties over time.
Description¶
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.
Tween is more suited than AnimationPlayer for animations where you don't know the final values in advance. For example, interpolating a dynamically-chosen camera zoom value is best done with a Tween node; it would be difficult to do the same thing with an AnimationPlayer node.
Here is a brief usage example that makes a 2D node move smoothly between two positions:
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()
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"
(e.g. 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 easings.net for some examples). The second accepts an EaseType constant, and controls where the 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.
Tween easing and transition types cheatsheet
Note: Tween methods will return false
if the requested operation cannot be completed.
Note: For an alternative method of tweening, that doesn't require using nodes, see SceneTreeTween.
Properties¶
|
||
|
||
|
Methods¶
follow_method ( Object object, String method, Variant initial_val, Object target, String target_method, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 ) |
|
follow_property ( Object object, NodePath property, Variant initial_val, Object target, NodePath target_property, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 ) |
|
get_runtime ( ) const |
|
interpolate_callback ( Object object, float duration, String callback, Variant arg1=null, Variant arg2=null, Variant arg3=null, Variant arg4=null, Variant arg5=null, Variant arg6=null, Variant arg7=null, Variant arg8=null ) |
|
interpolate_deferred_callback ( Object object, float duration, String callback, Variant arg1=null, Variant arg2=null, Variant arg3=null, Variant arg4=null, Variant arg5=null, Variant arg6=null, Variant arg7=null, Variant arg8=null ) |
|
interpolate_method ( Object object, String method, Variant initial_val, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 ) |
|
interpolate_property ( Object object, NodePath property, Variant initial_val, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 ) |
|
is_active ( ) const |
|
remove_all ( ) |
|
reset_all ( ) |
|
resume_all ( ) |
|
void |
set_active ( bool active ) |
start ( ) |
|
stop_all ( ) |
|
targeting_method ( Object object, String method, Object initial, String initial_method, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 ) |
|
targeting_property ( Object object, NodePath property, Object initial, NodePath initial_val, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 ) |
|
tell ( ) const |
Signals¶
tween_all_completed ( )
Emitted when all processes in a tween end.
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.
Enumerations¶
enum TweenProcessMode:
TweenProcessMode TWEEN_PROCESS_PHYSICS = 0
The tween updates with the _physics_process
callback.
TweenProcessMode TWEEN_PROCESS_IDLE = 1
The tween updates with the _process
callback.
enum TransitionType:
TransitionType TRANS_LINEAR = 0
The animation is interpolated linearly.
TransitionType TRANS_SINE = 1
The animation is interpolated using a sine function.
TransitionType TRANS_QUINT = 2
The animation is interpolated with a quintic (to the power of 5) function.
TransitionType TRANS_QUART = 3
The animation is interpolated with a quartic (to the power of 4) function.
TransitionType TRANS_QUAD = 4
The animation is interpolated with a quadratic (to the power of 2) function.
TransitionType TRANS_EXPO = 5
The animation is interpolated with an exponential (to the power of x) function.
TransitionType TRANS_ELASTIC = 6
The animation is interpolated with elasticity, wiggling around the edges.
TransitionType TRANS_CUBIC = 7
The animation is interpolated with a cubic (to the power of 3) function.
TransitionType TRANS_CIRC = 8
The animation is interpolated with a function using square roots.
TransitionType TRANS_BOUNCE = 9
The animation is interpolated by bouncing at the end.
TransitionType TRANS_BACK = 10
The animation is interpolated backing out at ends.
enum EaseType:
EaseType EASE_IN = 0
The interpolation starts slowly and speeds up towards the end.
EaseType EASE_OUT = 1
The interpolation starts quickly and slows down towards the end.
EaseType EASE_IN_OUT = 2
A combination of EASE_IN and EASE_OUT. The interpolation is slowest at both ends.
EaseType EASE_OUT_IN = 3
A combination of EASE_IN and EASE_OUT. The interpolation is fastest at both ends.
Property Descriptions¶
TweenProcessMode playback_process_mode = 1
void set_tween_process_mode ( TweenProcessMode value )
TweenProcessMode get_tween_process_mode ( )
The tween's animation process thread. See TweenProcessMode.
float playback_speed = 1.0
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 set_active or stop_all for this.
bool repeat = false
If true
, the tween loops.
Method Descriptions¶
bool follow_method ( Object object, String method, Variant initial_val, Object target, String target_method, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 )
Follows method
of object
and applies the returned value on target_method
of target
, beginning from initial_val
for duration
seconds, delay
later. Methods are called with consecutive values.
Use TransitionType for trans_type
and EaseType for ease_type
parameters. These values control the timing and direction of the interpolation. See the class description for more information.
bool follow_property ( Object object, NodePath property, Variant initial_val, Object target, NodePath target_property, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 )
Follows property
of object
and applies it on target_property
of target
, beginning from initial_val
for duration
seconds, delay
seconds later.
Use TransitionType for trans_type
and EaseType for ease_type
parameters. These values control the timing and direction of the interpolation. See the class description for more information.
float get_runtime ( ) const
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.
bool interpolate_callback ( Object object, float duration, String callback, Variant arg1=null, Variant arg2=null, Variant arg3=null, Variant arg4=null, Variant arg5=null, Variant arg6=null, Variant arg7=null, Variant arg8=null )
Calls callback
of object
after duration
. arg1
-arg5
are arguments to be passed to the callback.
bool interpolate_deferred_callback ( Object object, float duration, String callback, Variant arg1=null, Variant arg2=null, Variant arg3=null, Variant arg4=null, Variant arg5=null, Variant arg6=null, Variant arg7=null, Variant arg8=null )
Calls callback
of object
after duration
on the main thread (similar to Object.call_deferred). arg1
-arg5
are arguments to be passed to the callback.
bool interpolate_method ( Object object, String method, Variant initial_val, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 )
Animates method
of object
from initial_val
to final_val
for duration
seconds, delay
seconds later. Methods are called with consecutive values.
Use TransitionType for trans_type
and EaseType for ease_type
parameters. These values control the timing and direction of the interpolation. See the class description for more information.
bool interpolate_property ( Object object, NodePath property, Variant initial_val, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 )
Animates property
of object
from initial_val
to final_val
for duration
seconds, delay
seconds later. Setting the initial value to null
uses the current value of the property.
Use TransitionType for trans_type
and EaseType for ease_type
parameters. These values control the timing and direction of the interpolation. See the class description for more information.
bool is_active ( ) const
Returns true
if any tweens are currently running.
Note: This method doesn't consider tweens that have ended.
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.
bool remove_all ( )
Stops animation and removes all tweens.
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 reset, unless key
is specified.
bool reset_all ( )
Resets all tweens to their initial values (the ones given, not those before the tween).
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.
bool resume_all ( )
Continues animating all stopped tweens.
Sets the interpolation to the given time
in seconds.
void set_active ( bool active )
Activates/deactivates the tween. See also stop_all and resume_all.
bool start ( )
Starts the tween. You can define animations both before and after this.
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.
bool stop_all ( )
Stops animating all tweens.
bool targeting_method ( Object object, String method, Object initial, String initial_method, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 )
Animates method
of object
from the value returned by initial_method
to final_val
for duration
seconds, delay
seconds later. Methods are animated by calling them with consecutive values.
Use TransitionType for trans_type
and EaseType for ease_type
parameters. These values control the timing and direction of the interpolation. See the class description for more information.
bool targeting_property ( Object object, NodePath property, Object initial, NodePath initial_val, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 )
Animates property
of object
from the current value of the initial_val
property of initial
to final_val
for duration
seconds, delay
seconds later.
Use TransitionType for trans_type
and EaseType for ease_type
parameters. These values control the timing and direction of the interpolation. See the class description for more information.
float tell ( ) const
Returns the current time of the tween.