Tween

Inherits: Node < Object

Category: Core

Brief Description

Node useful for animations with unknown start and end points.

Member Functions

bool follow_method ( Object object, String method, Variant initial_val, Object target, String target_method, float times_in_sec, int trans_type, int ease_type, float delay=0 )
bool follow_property ( Object object, String property, Variant initial_val, Object target, String target_property, float times_in_sec, int trans_type, int ease_type, float delay=0 )
float get_runtime ( ) const
float get_speed ( ) const
int get_tween_process_mode ( ) const
bool interpolate_callback ( Object object, float times_in_sec, String callback, Variant arg1=NULL, Variant arg2=NULL, Variant arg3=NULL, Variant arg4=NULL, Variant arg5=NULL )
bool interpolate_deferred_callback ( Object object, float times_in_sec, String callback, Variant arg1=NULL, Variant arg2=NULL, Variant arg3=NULL, Variant arg4=NULL, Variant arg5=NULL )
bool interpolate_method ( Object object, String method, Variant initial_val, Variant final_val, float times_in_sec, int trans_type, int ease_type, float delay=0 )
bool interpolate_property ( Object object, String property, Variant initial_val, Variant final_val, float times_in_sec, int trans_type, int ease_type, float delay=0 )
bool is_active ( ) const
bool is_repeat ( ) const
bool remove ( Object object, String key )
bool remove_all ( )
bool reset ( Object object, String key )
bool reset_all ( )
bool resume ( Object object, String key )
bool resume_all ( )
bool seek ( float time )
void set_active ( bool active )
void set_repeat ( bool repeat )
void set_speed ( float speed )
void set_tween_process_mode ( int mode )
bool start ( )
bool stop ( Object object, String key )
bool stop_all ( )
bool targeting_method ( Object object, String method, Object initial, String initial_method, Variant final_val, float times_in_sec, int trans_type, int ease_type, float delay=0 )
bool targeting_property ( Object object, String property, Object initial, String initial_val, Variant final_val, float times_in_sec, int trans_type, int ease_type, float delay=0 )
float tell ( ) const

Signals

This signal is emitted when a tween ends.

This signal is emitted when a tween starts.

This signal is emitted each step of the tweening.

Numeric Constants

  • TWEEN_PROCESS_FIXED = 0 — The Tween should use _fixed_process for timekeeping when this is enabled.
  • TWEEN_PROCESS_IDLE = 1 — The Tween should use _process for timekeeping when this is enabled (default).
  • TRANS_LINEAR = 0 — Means that the animation is interpolated linearly.
  • TRANS_SINE = 1 — Means that the animation is interpolated using a sine wave.
  • TRANS_QUINT = 2 — Means that the animation is interpolated with a quinary (to the power of 5) function.
  • TRANS_QUART = 3 — Means that the animation is interpolated with a quartic (to the power of 4) function.
  • TRANS_QUAD = 4 — Means that the animation is interpolated with a quadratic (to the power of 2) function.
  • TRANS_EXPO = 5 — Means that the animation is interpolated with a exponential (some number to the power of x) function.
  • TRANS_ELASTIC = 6 — Means that the animation is interpolated with elasticity, wiggling around the edges.
  • TRANS_CUBIC = 7 — Means that the animation is interpolated with a cubic (to the power of 3) function.
  • TRANS_CIRC = 8 — Means that the animation is interpolated with a function using square roots.
  • TRANS_BOUNCE = 9 — Means that the animation is interpolated by bouncing at, but never surpassing, the end.
  • TRANS_BACK = 10 — Means that the animation is interpolated backing out at edges.
  • EASE_IN = 0 — Signifies that the interpolation should be focused in the beginning.
  • EASE_OUT = 1 — Signifies that the interpolation should be focused in the end.
  • EASE_IN_OUT = 2 — Signifies that the interpolation should be focused in both ends.
  • EASE_OUT_IN = 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).

Description

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:

var tween = get_node("Tween")
tween.interpolate_property(get_node("Node2D_to_move"), "transform/pos", Vector2(0,0), Vector2(100,100), 1, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
tween.start()

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 begining, the end, or both). If you don’t know which transision and easing to pick, you can try different TRANS_* constants with EASE_IN_OUT, and use the one that looks best.

Member Function Description

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

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

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

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

  • float get_runtime ( ) const

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.

  • float get_speed ( ) const

Returns the speed that has been set from editor GUI or set_repeat.

  • int get_tween_process_mode ( ) const

Returns the process mode that has been set from editor GUI or set_tween_process_mode

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

Call callback of object after times_in_sec on the main thread (similar to methog Object.call_deferred). [codearg1``-arg5 are arguments to be passed to the callback.

Animate method of object from initial_val to final_val for times_in_sec seconds, delay seconds later. Methods are animated by calling them with consecuitive values.

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

Animate property of object from initial_val to final_val for times_in_sec seconds, delay seconds later.

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

  • bool is_active ( ) const

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

  • bool is_repeat ( ) const

Returns true if repeat has been set from editor GUI or set_repeat.

Stop animating and completely remove a tween, given its object and property/method pair.

  • bool remove_all ( )

Stop animating and completely remove all tweens.

Resets a tween to the initial value (the one given, not the one before the tween), given its object and property/method pair.

  • bool reset_all ( )

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

Continue animating a stopped tween, given its object and property/method pair.

  • bool resume_all ( )

Continue animating all stopped tweens.

Seek the animation to the given time in seconds.

  • void set_active ( bool active )

Activate/deactivate the tween. You can use this for pausing animations, though stop_all and resume_all might be more fit for this.

  • void set_repeat ( bool repeat )

Make the tween repeat after all tweens have finished.

  • void set_speed ( float speed )

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 set_active or stop_all and resume_all for this.

  • void set_tween_process_mode ( int mode )

Set whether the Tween uses _process or _fixed_process (accepts TWEEN_PROCESS_IDLE and TWEEN_PROCESS_FIXED constants, respectively).

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

Stop animating a tween, given its object and property/method pair.

Stop animating all tweens.

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

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

Animate property of object from the current value of the initial_val property of initial to final_val for times_in_sec seconds, delay seconds later.

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

Returns the current time of the tween.