123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546 |
- :github_url: hide
- .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
- .. DO NOT EDIT THIS FILE, but the Tween.xml source instead.
- .. The source is found in doc/classes or modules/<name>/doc_classes.
- .. _class_Tween:
- Tween
- =====
- **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
- Lightweight object used for general-purpose animation via script, using :ref:`Tweener<class_Tweener>`\ s.
- Description
- -----------
- Tweens are mostly 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 :ref:`AnimationPlayer<class_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``; it would be difficult to do the same thing with an :ref:`AnimationPlayer<class_AnimationPlayer>` node. Tweens are also more light-weight than :ref:`AnimationPlayer<class_AnimationPlayer>`, so they are very much suited for simple animations or general tasks that don't require visual tweaking provided by the editor. They can be used in a fire-and-forget manner for some logic that normally would be done by code. You can e.g. make something shoot periodically by using a looped :ref:`CallbackTweener<class_CallbackTweener>` with a delay.
- A ``Tween`` can be created by using either :ref:`SceneTree.create_tween<class_SceneTree_method_create_tween>` or :ref:`Node.create_tween<class_Node_method_create_tween>`. ``Tween``\ s created manually (i.e. by using ``Tween.new()``) are invalid. They can't be used for tweening values, but you can do manual interpolation with :ref:`interpolate_value<class_Tween_method_interpolate_value>`.
- A ``Tween`` animation is composed of a sequence of :ref:`Tweener<class_Tweener>`\ s, which by default are executed one after another. You can create a sequence by appending :ref:`Tweener<class_Tweener>`\ s to the ``Tween``. Animating something with a :ref:`Tweener<class_Tweener>` is called tweening. Example tweening sequence looks like this:
- ::
- var tween = get_tree().create_tween()
- tween.tween_property($Sprite, "modulate", Color.red, 1)
- tween.tween_property($Sprite, "scale", Vector2(), 1)
- tween.tween_callback($Sprite.queue_free)
- This sequence will make the ``$Sprite`` node turn red, then shrink and finally the :ref:`Node.queue_free<class_Node_method_queue_free>` is called to remove the sprite. See methods :ref:`tween_property<class_Tween_method_tween_property>`, :ref:`tween_interval<class_Tween_method_tween_interval>`, :ref:`tween_callback<class_Tween_method_tween_callback>` and :ref:`tween_method<class_Tween_method_tween_method>` for more usage information.
- When a :ref:`Tweener<class_Tweener>` is created with one of the ``tween_*`` methods, a chained method call can be used to tweak the properties of this :ref:`Tweener<class_Tweener>`. For example, if you want to set different transition type in the above example, you can do:
- ::
- var tween = get_tree().create_tween()
- tween.tween_property($Sprite, "modulate", Color.red, 1).set_trans(Tween.TRANS_SINE)
- tween.tween_property($Sprite, "scale", Vector2(), 1).set_trans(Tween.TRANS_BOUNCE)
- tween.tween_callback($Sprite.queue_free)
- Most of the ``Tween`` methods can be chained this way too. In this example the ``Tween`` is bound and have set a default transition:
- ::
- var tween = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_ELASTIC)
- tween.tween_property($Sprite, "modulate", Color.red, 1)
- tween.tween_property($Sprite, "scale", Vector2(), 1)
- tween.tween_callback($Sprite.queue_free)
- Another interesting use for ``Tween``\ s is animating arbitrary set of objects:
- ::
- var tween = create_tween()
- for sprite in get_children():
- tween.tween_property(sprite, "position", Vector2(), 1)
- In the example above, all children of a node are moved one after another to position (0, 0).
- Some :ref:`Tweener<class_Tweener>`\ s use transitions and eases. The first accepts an :ref:`TransitionType<enum_Tween_TransitionType>` constant, and refers to the way the timing of the animation is handled (see `easings.net <https://easings.net/>`__ for some examples). The second accepts an :ref:`EaseType<enum_Tween_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 :ref:`TransitionType<enum_Tween_TransitionType>` constants with :ref:`EASE_IN_OUT<class_Tween_constant_EASE_IN_OUT>`, and use the one that looks best.
- \ `Tween easing and transition types cheatsheet <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/tween_cheatsheet.png>`__\
- \ **Note:** All ``Tween``\ s will automatically start by default. To prevent a ``Tween`` from autostarting, you can call :ref:`stop<class_Tween_method_stop>` immediately after it was created.
- Methods
- -------
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`bind_node<class_Tween_method_bind_node>` **(** :ref:`Node<class_Node>` node **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`chain<class_Tween_method_chain>` **(** **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`custom_step<class_Tween_method_custom_step>` **(** :ref:`float<class_float>` delta **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Variant<class_Variant>` | :ref:`interpolate_value<class_Tween_method_interpolate_value>` **(** :ref:`Variant<class_Variant>` initial_value, :ref:`Variant<class_Variant>` delta_value, :ref:`float<class_float>` elapsed_time, :ref:`float<class_float>` duration, :ref:`TransitionType<enum_Tween_TransitionType>` trans_type, :ref:`EaseType<enum_Tween_EaseType>` ease_type **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_running<class_Tween_method_is_running>` **(** **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_valid<class_Tween_method_is_valid>` **(** **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`kill<class_Tween_method_kill>` **(** **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`parallel<class_Tween_method_parallel>` **(** **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`pause<class_Tween_method_pause>` **(** **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`play<class_Tween_method_play>` **(** **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_ease<class_Tween_method_set_ease>` **(** :ref:`EaseType<enum_Tween_EaseType>` ease **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_loops<class_Tween_method_set_loops>` **(** :ref:`int<class_int>` loops=0 **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_parallel<class_Tween_method_set_parallel>` **(** :ref:`bool<class_bool>` parallel=true **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_pause_mode<class_Tween_method_set_pause_mode>` **(** :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>` mode **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_process_mode<class_Tween_method_set_process_mode>` **(** :ref:`TweenProcessMode<enum_Tween_TweenProcessMode>` mode **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_speed_scale<class_Tween_method_set_speed_scale>` **(** :ref:`float<class_float>` speed **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_trans<class_Tween_method_set_trans>` **(** :ref:`TransitionType<enum_Tween_TransitionType>` trans **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`stop<class_Tween_method_stop>` **(** **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`CallbackTweener<class_CallbackTweener>` | :ref:`tween_callback<class_Tween_method_tween_callback>` **(** :ref:`Callable<class_Callable>` callback **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`IntervalTweener<class_IntervalTweener>` | :ref:`tween_interval<class_Tween_method_tween_interval>` **(** :ref:`float<class_float>` time **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`MethodTweener<class_MethodTweener>` | :ref:`tween_method<class_Tween_method_tween_method>` **(** :ref:`Callable<class_Callable>` method, :ref:`Variant<class_Variant>` from, :ref:`Variant<class_Variant>` to, :ref:`float<class_float>` duration **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`PropertyTweener<class_PropertyTweener>` | :ref:`tween_property<class_Tween_method_tween_property>` **(** :ref:`Object<class_Object>` object, :ref:`NodePath<class_NodePath>` property, :ref:`Variant<class_Variant>` final_val, :ref:`float<class_float>` duration **)** |
- +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- Signals
- -------
- .. _class_Tween_signal_finished:
- - **finished** **(** **)**
- Emitted when the ``Tween`` has finished all tweening. Never emitted when the ``Tween`` is set to infinite looping (see :ref:`set_loops<class_Tween_method_set_loops>`).
- \ **Note:** The ``Tween`` is removed (invalidated) after this signal is emitted, but it doesn't happen immediately, but on the next processing frame. Calling :ref:`stop<class_Tween_method_stop>` inside the signal callback will preserve the ``Tween``.
- ----
- .. _class_Tween_signal_loop_finished:
- - **loop_finished** **(** :ref:`int<class_int>` loop_count **)**
- Emitted when a full loop is complete (see :ref:`set_loops<class_Tween_method_set_loops>`), providing the loop index. This signal is not emitted after final loop, use :ref:`finished<class_Tween_signal_finished>` instead for this case.
- ----
- .. _class_Tween_signal_step_finished:
- - **step_finished** **(** :ref:`int<class_int>` idx **)**
- Emitted when one step of the ``Tween`` is complete, providing the step index. One step is either a single :ref:`Tweener<class_Tweener>` or a group of :ref:`Tweener<class_Tweener>`\ s running parallelly.
- Enumerations
- ------------
- .. _enum_Tween_TweenProcessMode:
- .. _class_Tween_constant_TWEEN_PROCESS_PHYSICS:
- .. _class_Tween_constant_TWEEN_PROCESS_IDLE:
- enum **TweenProcessMode**:
- - **TWEEN_PROCESS_PHYSICS** = **0** --- The ``Tween`` updates during the physics frame.
- - **TWEEN_PROCESS_IDLE** = **1** --- The ``Tween`` updates during the idle frame.
- ----
- .. _enum_Tween_TweenPauseMode:
- .. _class_Tween_constant_TWEEN_PAUSE_BOUND:
- .. _class_Tween_constant_TWEEN_PAUSE_STOP:
- .. _class_Tween_constant_TWEEN_PAUSE_PROCESS:
- enum **TweenPauseMode**:
- - **TWEEN_PAUSE_BOUND** = **0** --- If the ``Tween`` has a bound node, it will process when that node can process (see :ref:`Node.process_mode<class_Node_property_process_mode>`). Otherwise it's the same as :ref:`TWEEN_PAUSE_STOP<class_Tween_constant_TWEEN_PAUSE_STOP>`.
- - **TWEEN_PAUSE_STOP** = **1** --- If :ref:`SceneTree<class_SceneTree>` is paused, the ``Tween`` will also pause.
- - **TWEEN_PAUSE_PROCESS** = **2** --- The ``Tween`` will process regardless of whether :ref:`SceneTree<class_SceneTree>` is paused.
- ----
- .. _enum_Tween_TransitionType:
- .. _class_Tween_constant_TRANS_LINEAR:
- .. _class_Tween_constant_TRANS_SINE:
- .. _class_Tween_constant_TRANS_QUINT:
- .. _class_Tween_constant_TRANS_QUART:
- .. _class_Tween_constant_TRANS_QUAD:
- .. _class_Tween_constant_TRANS_EXPO:
- .. _class_Tween_constant_TRANS_ELASTIC:
- .. _class_Tween_constant_TRANS_CUBIC:
- .. _class_Tween_constant_TRANS_CIRC:
- .. _class_Tween_constant_TRANS_BOUNCE:
- .. _class_Tween_constant_TRANS_BACK:
- enum **TransitionType**:
- - **TRANS_LINEAR** = **0** --- The animation is interpolated linearly.
- - **TRANS_SINE** = **1** --- The animation is interpolated using a sine function.
- - **TRANS_QUINT** = **2** --- The animation is interpolated with a quintic (to the power of 5) function.
- - **TRANS_QUART** = **3** --- The animation is interpolated with a quartic (to the power of 4) function.
- - **TRANS_QUAD** = **4** --- The animation is interpolated with a quadratic (to the power of 2) function.
- - **TRANS_EXPO** = **5** --- The animation is interpolated with an exponential (to the power of x) function.
- - **TRANS_ELASTIC** = **6** --- The animation is interpolated with elasticity, wiggling around the edges.
- - **TRANS_CUBIC** = **7** --- The animation is interpolated with a cubic (to the power of 3) function.
- - **TRANS_CIRC** = **8** --- The animation is interpolated with a function using square roots.
- - **TRANS_BOUNCE** = **9** --- The animation is interpolated by bouncing at the end.
- - **TRANS_BACK** = **10** --- The animation is interpolated backing out at ends.
- ----
- .. _enum_Tween_EaseType:
- .. _class_Tween_constant_EASE_IN:
- .. _class_Tween_constant_EASE_OUT:
- .. _class_Tween_constant_EASE_IN_OUT:
- .. _class_Tween_constant_EASE_OUT_IN:
- enum **EaseType**:
- - **EASE_IN** = **0** --- The interpolation starts slowly and speeds up towards the end.
- - **EASE_OUT** = **1** --- The interpolation starts quickly and slows down towards the end.
- - **EASE_IN_OUT** = **2** --- A combination of :ref:`EASE_IN<class_Tween_constant_EASE_IN>` and :ref:`EASE_OUT<class_Tween_constant_EASE_OUT>`. The interpolation is slowest at both ends.
- - **EASE_OUT_IN** = **3** --- A combination of :ref:`EASE_IN<class_Tween_constant_EASE_IN>` and :ref:`EASE_OUT<class_Tween_constant_EASE_OUT>`. The interpolation is fastest at both ends.
- Method Descriptions
- -------------------
- .. _class_Tween_method_bind_node:
- - :ref:`Tween<class_Tween>` **bind_node** **(** :ref:`Node<class_Node>` node **)**
- Binds this ``Tween`` with the given ``node``. ``Tween``\ s are processed directly by the :ref:`SceneTree<class_SceneTree>`, so they run independently of the animated nodes. When you bind a :ref:`Node<class_Node>` with the ``Tween``, the ``Tween`` will halt the animation when the object is not inside tree and the ``Tween`` will be automatically killed when the bound object is freed. Also :ref:`TWEEN_PAUSE_BOUND<class_Tween_constant_TWEEN_PAUSE_BOUND>` will make the pausing behavior dependent on the bound node.
- For a shorter way to create and bind a ``Tween``, you can use :ref:`Node.create_tween<class_Node_method_create_tween>`.
- ----
- .. _class_Tween_method_chain:
- - :ref:`Tween<class_Tween>` **chain** **(** **)**
- Used to chain two :ref:`Tweener<class_Tweener>`\ s after :ref:`set_parallel<class_Tween_method_set_parallel>` is called with ``true``.
- ::
- var tween = create_tween().set_parallel(true)
- tween.tween_property(...)
- tween.tween_property(...) # Will run parallelly with above.
- tween.chain().tween_property(...) # Will run after two above are finished.
- ----
- .. _class_Tween_method_custom_step:
- - :ref:`bool<class_bool>` **custom_step** **(** :ref:`float<class_float>` delta **)**
- Processes the ``Tween`` by given ``delta`` value, in seconds. Mostly useful when the ``Tween`` is paused, for controlling it manually. Can also be used to end the ``Tween`` animation immediately, by using ``delta`` longer than the whole duration.
- Returns ``true`` if the ``Tween`` still has :ref:`Tweener<class_Tweener>`\ s that haven't finished.
- \ **Note:** The ``Tween`` will become invalid after finished, but you can call :ref:`stop<class_Tween_method_stop>` after the step, to keep it and reset.
- ----
- .. _class_Tween_method_interpolate_value:
- - :ref:`Variant<class_Variant>` **interpolate_value** **(** :ref:`Variant<class_Variant>` initial_value, :ref:`Variant<class_Variant>` delta_value, :ref:`float<class_float>` elapsed_time, :ref:`float<class_float>` duration, :ref:`TransitionType<enum_Tween_TransitionType>` trans_type, :ref:`EaseType<enum_Tween_EaseType>` ease_type **)**
- This method can be used for manual interpolation of a value, when you don't want ``Tween`` to do animating for you. It's similar to :ref:`@GlobalScope.lerp<class_@GlobalScope_method_lerp>`, but with support for custom transition and easing.
- \ ``initial_value`` is the starting value of the interpolation.
- \ ``delta_value`` is the change of the value in the interpolation, i.e. it's equal to ``final_value - initial_value``.
- \ ``elapsed_time`` is the time in seconds that passed after the interpolation started and it's used to control the position of the interpolation. E.g. when it's equal to half of the ``duration``, the interpolated value will be halfway between initial and final values. This value can also be greater than ``duration`` or lower than 0, which will extrapolate the value.
- \ ``duration`` is the total time of the interpolation.
- \ **Note:** If ``duration`` is equal to ``0``, the method will always return the final value, regardless of ``elapsed_time`` provided.
- ----
- .. _class_Tween_method_is_running:
- - :ref:`bool<class_bool>` **is_running** **(** **)**
- Returns whether the ``Tween`` is currently running, i.e. it wasn't paused and it's not finished.
- ----
- .. _class_Tween_method_is_valid:
- - :ref:`bool<class_bool>` **is_valid** **(** **)**
- Returns whether the ``Tween`` is valid. A valid ``Tween`` is a ``Tween`` contained by the scene tree (i.e. the array from :ref:`SceneTree.get_processed_tweens<class_SceneTree_method_get_processed_tweens>` will contain this ``Tween``). ``Tween`` might become invalid when it has finished tweening or was killed, also when created with ``Tween.new()``. Invalid ``Tween`` can't have :ref:`Tweener<class_Tweener>`\ s appended, because it can't animate them. You can however still use :ref:`interpolate_value<class_Tween_method_interpolate_value>`.
- ----
- .. _class_Tween_method_kill:
- - void **kill** **(** **)**
- Aborts all tweening operations and invalidates the ``Tween``.
- ----
- .. _class_Tween_method_parallel:
- - :ref:`Tween<class_Tween>` **parallel** **(** **)**
- Makes the next :ref:`Tweener<class_Tweener>` run parallelly to the previous one. Example:
- ::
- var tween = create_tween()
- tween.tween_property(...)
- tween.parallel().tween_property(...)
- tween.parallel().tween_property(...)
- All :ref:`Tweener<class_Tweener>`\ s in the example will run at the same time.
- You can make the ``Tween`` parallel by default by using :ref:`set_parallel<class_Tween_method_set_parallel>`.
- ----
- .. _class_Tween_method_pause:
- - void **pause** **(** **)**
- Pauses the tweening. The animation can be resumed by using :ref:`play<class_Tween_method_play>`.
- ----
- .. _class_Tween_method_play:
- - void **play** **(** **)**
- Resumes a paused or stopped ``Tween``.
- ----
- .. _class_Tween_method_set_ease:
- - :ref:`Tween<class_Tween>` **set_ease** **(** :ref:`EaseType<enum_Tween_EaseType>` ease **)**
- Sets the default ease type for :ref:`PropertyTweener<class_PropertyTweener>`\ s and :ref:`MethodTweener<class_MethodTweener>`\ s animated by this ``Tween``.
- ----
- .. _class_Tween_method_set_loops:
- - :ref:`Tween<class_Tween>` **set_loops** **(** :ref:`int<class_int>` loops=0 **)**
- Sets the number of times the tweening sequence will be repeated, i.e. ``set_loops(2)`` will run the animation twice.
- Calling this method without arguments will make the ``Tween`` run infinitely, until it is either killed by :ref:`kill<class_Tween_method_kill>` or by freeing bound node, or all the animated objects have been freed (which makes further animation impossible).
- \ **Warning:** Make sure to always add some duration/delay when using infinite loops. 0-duration looped animations (e.g. single :ref:`CallbackTweener<class_CallbackTweener>` with no delay or :ref:`PropertyTweener<class_PropertyTweener>` with invalid node) are equivalent to infinite ``while`` loops and will freeze your game. If a ``Tween``'s lifetime depends on some node, always use :ref:`bind_node<class_Tween_method_bind_node>`.
- ----
- .. _class_Tween_method_set_parallel:
- - :ref:`Tween<class_Tween>` **set_parallel** **(** :ref:`bool<class_bool>` parallel=true **)**
- If ``parallel`` is ``true``, the :ref:`Tweener<class_Tweener>`\ s appended after this method will by default run simultaneously, as opposed to sequentially.
- ----
- .. _class_Tween_method_set_pause_mode:
- - :ref:`Tween<class_Tween>` **set_pause_mode** **(** :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>` mode **)**
- Determines the behavior of the ``Tween`` when the :ref:`SceneTree<class_SceneTree>` is paused. Check :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>` for options.
- Default value is :ref:`TWEEN_PAUSE_BOUND<class_Tween_constant_TWEEN_PAUSE_BOUND>`.
- ----
- .. _class_Tween_method_set_process_mode:
- - :ref:`Tween<class_Tween>` **set_process_mode** **(** :ref:`TweenProcessMode<enum_Tween_TweenProcessMode>` mode **)**
- Determines whether the ``Tween`` should run during idle frame (see :ref:`Node._process<class_Node_method__process>`) or physics frame (see :ref:`Node._physics_process<class_Node_method__physics_process>`.
- Default value is :ref:`TWEEN_PROCESS_IDLE<class_Tween_constant_TWEEN_PROCESS_IDLE>`.
- ----
- .. _class_Tween_method_set_speed_scale:
- - :ref:`Tween<class_Tween>` **set_speed_scale** **(** :ref:`float<class_float>` speed **)**
- Scales the speed of tweening. This affects all :ref:`Tweener<class_Tweener>`\ s and their delays.
- ----
- .. _class_Tween_method_set_trans:
- - :ref:`Tween<class_Tween>` **set_trans** **(** :ref:`TransitionType<enum_Tween_TransitionType>` trans **)**
- Sets the default transition type for :ref:`PropertyTweener<class_PropertyTweener>`\ s and :ref:`MethodTweener<class_MethodTweener>`\ s animated by this ``Tween``.
- ----
- .. _class_Tween_method_stop:
- - void **stop** **(** **)**
- Stops the tweening and resets the ``Tween`` to its initial state. This will not remove any appended :ref:`Tweener<class_Tweener>`\ s.
- ----
- .. _class_Tween_method_tween_callback:
- - :ref:`CallbackTweener<class_CallbackTweener>` **tween_callback** **(** :ref:`Callable<class_Callable>` callback **)**
- Creates and appends a :ref:`CallbackTweener<class_CallbackTweener>`. This method can be used to call an arbitrary method in any object. Use :ref:`Callable.bind<class_Callable_method_bind>` to bind additional arguments for the call.
- Example: object that keeps shooting every 1 second.
- ::
- var tween = get_tree().create_tween().set_loops()
- tween.tween_callback(shoot).set_delay(1)
- Example: turning a sprite red and then blue, with 2 second delay.
- ::
- var tween = get_tree().create_tween()
- tween.tween_callback($Sprite.set_modulate.bind(Color.red)).set_delay(2)
- tween.tween_callback($Sprite.set_modulate.bind(Color.blue)).set_delay(2)
- ----
- .. _class_Tween_method_tween_interval:
- - :ref:`IntervalTweener<class_IntervalTweener>` **tween_interval** **(** :ref:`float<class_float>` time **)**
- Creates and appends an :ref:`IntervalTweener<class_IntervalTweener>`. This method can be used to create delays in the tween animation, as an alternative for using the delay in other :ref:`Tweener<class_Tweener>`\ s or when there's no animation (in which case the ``Tween`` acts as a timer). ``time`` is the length of the interval, in seconds.
- Example: creating an interval in code execution.
- ::
- # ... some code
- await create_tween().tween_interval(2).finished
- # ... more code
- Example: creating an object that moves back and forth and jumps every few seconds.
- ::
- var tween = create_tween().set_loops()
- tween.tween_property("position:x", 200, 1).as_relative()
- tween.tween_callback(jump)
- tween.tween_interval(2)
- tween.tween_property("position:x", -200, 1).as_relative()
- tween.tween_callback(jump)
- tween.tween_interval(2)
- ----
- .. _class_Tween_method_tween_method:
- - :ref:`MethodTweener<class_MethodTweener>` **tween_method** **(** :ref:`Callable<class_Callable>` method, :ref:`Variant<class_Variant>` from, :ref:`Variant<class_Variant>` to, :ref:`float<class_float>` duration **)**
- Creates and appends a :ref:`MethodTweener<class_MethodTweener>`. This method is similar to a combination of :ref:`tween_callback<class_Tween_method_tween_callback>` and :ref:`tween_property<class_Tween_method_tween_property>`. It calls a method over time with a tweened value provided as an argument. The value is tweened between ``from`` and ``to`` over the time specified by ``duration``, in seconds. Use :ref:`Callable.bind<class_Callable_method_bind>` to bind additional arguments for the call. You can use :ref:`MethodTweener.set_ease<class_MethodTweener_method_set_ease>` and :ref:`MethodTweener.set_trans<class_MethodTweener_method_set_trans>` to tweak the easing and transition of the value or :ref:`MethodTweener.set_delay<class_MethodTweener_method_set_delay>` to delay the tweening.
- Example: making a 3D object look from one point to another point.
- ::
- var tween = create_tween()
- tween.tween_method(look_at.bind(Vector3.UP), Vector3(-1, 0, -1), Vector3(1, 0, -1), 1) # The look_at() method takes up vector as second argument.
- Example: setting a text of a :ref:`Label<class_Label>`, using an intermediate method and after a delay.
- ::
- func _ready():
- var tween = create_tween()
- tween.tween_method(set_label_text, 0, 10, 1).set_delay(1)
-
- func set_label_text(value: int):
- $Label.text = "Counting " + str(value)
- ----
- .. _class_Tween_method_tween_property:
- - :ref:`PropertyTweener<class_PropertyTweener>` **tween_property** **(** :ref:`Object<class_Object>` object, :ref:`NodePath<class_NodePath>` property, :ref:`Variant<class_Variant>` final_val, :ref:`float<class_float>` duration **)**
- Creates and appends a :ref:`PropertyTweener<class_PropertyTweener>`. This method tweens a ``property`` of an ``object`` between an initial value and ``final_val`` in a span of time equal to ``duration``, in seconds. The initial value by default is a value at the time the tweening of the :ref:`PropertyTweener<class_PropertyTweener>` start. For example:
- ::
- var tween = create_tween()
- tween.tween_property($Sprite, "position", Vector2(100, 200)
- tween.tween_property($Sprite, "position", Vector2(200, 300)
- will move the sprite to position (100, 200) and then to (200, 300). If you use :ref:`PropertyTweener.from<class_PropertyTweener_method_from>` or :ref:`PropertyTweener.from_current<class_PropertyTweener_method_from_current>`, the starting position will be overwritten by the given value instead. See other methods in :ref:`PropertyTweener<class_PropertyTweener>` to see how the tweening can be tweaked further.
- \ **Note:** 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.
- Example: moving object twice from the same position, with different transition types.
- ::
- var tween = create_tween()
- tween.tween_property($Sprite, "position", Vector2.RIGHT * 300).as_relative().set_trans(Tween.TRANS_SINE)
- tween.tween_property($Sprite, "position", Vector2.RIGHT * 300).as_relative().from_current().set_trans(Tween.TRANS_EXPO)
- .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
- .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
- .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
- .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
- .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
- .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
|