12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091 |
- :github_url: hide
- .. DO NOT EDIT THIS FILE!!!
- .. Generated automatically from Godot engine sources.
- .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
- .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Tween.xml.
- .. _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.
- .. rst-class:: classref-introduction-group
- 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. Animating something with a **Tween** is called tweening.
- \ **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 and can't be used for tweening values.
- A tween animation is created by adding :ref:`Tweener<class_Tweener>`\ s to the **Tween** object, using :ref:`tween_property()<class_Tween_method_tween_property>`, :ref:`tween_interval()<class_Tween_method_tween_interval>`, :ref:`tween_callback()<class_Tween_method_tween_callback>` or :ref:`tween_method()<class_Tween_method_tween_method>`:
- .. tabs::
- .. code-tab:: gdscript
- 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)
- .. code-tab:: csharp
- Tween tween = GetTree().CreateTween();
- tween.TweenProperty(GetNode("Sprite"), "modulate", Colors.Red, 1.0f);
- tween.TweenProperty(GetNode("Sprite"), "scale", Vector2.Zero, 1.0f);
- tween.TweenCallback(Callable.From(GetNode("Sprite").QueueFree));
- This sequence will make the ``$Sprite`` node turn red, then shrink, before finally calling :ref:`Node.queue_free()<class_Node_method_queue_free>` to free the sprite. :ref:`Tweener<class_Tweener>`\ s are executed one after another by default. This behavior can be changed using :ref:`parallel()<class_Tween_method_parallel>` and :ref:`set_parallel()<class_Tween_method_set_parallel>`.
- 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 a different transition type in the above example, you can use :ref:`set_trans()<class_Tween_method_set_trans>`:
- .. tabs::
- .. code-tab:: gdscript
- 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)
- .. code-tab:: csharp
- Tween tween = GetTree().CreateTween();
- tween.TweenProperty(GetNode("Sprite"), "modulate", Colors.Red, 1.0f).SetTrans(Tween.TransitionType.Sine);
- tween.TweenProperty(GetNode("Sprite"), "scale", Vector2.Zero, 1.0f).SetTrans(Tween.TransitionType.Bounce);
- tween.TweenCallback(Callable.From(GetNode("Sprite").QueueFree));
- Most of the **Tween** methods can be chained this way too. In the following example the **Tween** is bound to the running script's node and a default transition is set for its :ref:`Tweener<class_Tweener>`\ s:
- .. tabs::
- .. code-tab:: gdscript
- 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)
- .. code-tab:: csharp
- var tween = GetTree().CreateTween().BindNode(this).SetTrans(Tween.TransitionType.Elastic);
- tween.TweenProperty(GetNode("Sprite"), "modulate", Colors.Red, 1.0f);
- tween.TweenProperty(GetNode("Sprite"), "scale", Vector2.Zero, 1.0f);
- tween.TweenCallback(Callable.From(GetNode("Sprite").QueueFree));
- Another interesting use for **Tween**\ s is animating arbitrary sets of objects:
- .. tabs::
- .. code-tab:: gdscript
- var tween = create_tween()
- for sprite in get_children():
- tween.tween_property(sprite, "position", Vector2(0, 0), 1)
- .. code-tab:: csharp
- Tween tween = CreateTween();
- foreach (Node sprite in GetChildren())
- tween.TweenProperty(sprite, "position", Vector2.Zero, 1.0f);
- In the example above, all children of a node are moved one after another to position (0, 0).
- You should avoid using more than one **Tween** per object's property. If two or more tweens animate one property at the same time, the last one created will take priority and assign the final value. If you want to interrupt and restart an animation, consider assigning the **Tween** to a variable:
- .. tabs::
- .. code-tab:: gdscript
- var tween
- func animate():
- if tween:
- tween.kill() # Abort the previous animation.
- tween = create_tween()
- .. code-tab:: csharp
- private Tween _tween;
-
- public void Animate()
- {
- if (_tween != null)
- _tween.Kill(); // Abort the previous animation
- _tween = CreateTween();
- }
- Some :ref:`Tweener<class_Tweener>`\ s use transitions and eases. The first accepts a :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.webp>`__\
- \ **Note:** Tweens are not designed to be reused and trying to do so results in an undefined behavior. Create a new Tween for each animation and every time you replay an animation from start. Keep in mind that Tweens start immediately, so only create a Tween when you want to start animating.
- \ **Note:** The tween is processed after all of the nodes in the current frame, i.e. node's :ref:`Node._process()<class_Node_private_method__process>` method would be called before the tween (or :ref:`Node._physics_process()<class_Node_private_method__physics_process>` depending on the value passed to :ref:`set_process_mode()<class_Tween_method_set_process_mode>`).
- .. rst-class:: classref-reftable-group
- Methods
- -------
- .. table::
- :widths: auto
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`bind_node<class_Tween_method_bind_node>`\ (\ node\: :ref:`Node<class_Node>`\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`chain<class_Tween_method_chain>`\ (\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`custom_step<class_Tween_method_custom_step>`\ (\ delta\: :ref:`float<class_float>`\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_loops_left<class_Tween_method_get_loops_left>`\ (\ ) |const| |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`get_total_elapsed_time<class_Tween_method_get_total_elapsed_time>`\ (\ ) |const| |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Variant<class_Variant>` | :ref:`interpolate_value<class_Tween_method_interpolate_value>`\ (\ initial_value\: :ref:`Variant<class_Variant>`, delta_value\: :ref:`Variant<class_Variant>`, elapsed_time\: :ref:`float<class_float>`, duration\: :ref:`float<class_float>`, trans_type\: :ref:`TransitionType<enum_Tween_TransitionType>`, ease_type\: :ref:`EaseType<enum_Tween_EaseType>`\ ) |static| |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :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>`\ (\ ease\: :ref:`EaseType<enum_Tween_EaseType>`\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_ignore_time_scale<class_Tween_method_set_ignore_time_scale>`\ (\ ignore\: :ref:`bool<class_bool>` = true\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_loops<class_Tween_method_set_loops>`\ (\ loops\: :ref:`int<class_int>` = 0\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_parallel<class_Tween_method_set_parallel>`\ (\ parallel\: :ref:`bool<class_bool>` = true\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_pause_mode<class_Tween_method_set_pause_mode>`\ (\ mode\: :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>`\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_process_mode<class_Tween_method_set_process_mode>`\ (\ mode\: :ref:`TweenProcessMode<enum_Tween_TweenProcessMode>`\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_speed_scale<class_Tween_method_set_speed_scale>`\ (\ speed\: :ref:`float<class_float>`\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Tween<class_Tween>` | :ref:`set_trans<class_Tween_method_set_trans>`\ (\ trans\: :ref:`TransitionType<enum_Tween_TransitionType>`\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | |void| | :ref:`stop<class_Tween_method_stop>`\ (\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`CallbackTweener<class_CallbackTweener>` | :ref:`tween_callback<class_Tween_method_tween_callback>`\ (\ callback\: :ref:`Callable<class_Callable>`\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`IntervalTweener<class_IntervalTweener>` | :ref:`tween_interval<class_Tween_method_tween_interval>`\ (\ time\: :ref:`float<class_float>`\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`MethodTweener<class_MethodTweener>` | :ref:`tween_method<class_Tween_method_tween_method>`\ (\ method\: :ref:`Callable<class_Callable>`, from\: :ref:`Variant<class_Variant>`, to\: :ref:`Variant<class_Variant>`, duration\: :ref:`float<class_float>`\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`PropertyTweener<class_PropertyTweener>` | :ref:`tween_property<class_Tween_method_tween_property>`\ (\ object\: :ref:`Object<class_Object>`, property\: :ref:`NodePath<class_NodePath>`, final_val\: :ref:`Variant<class_Variant>`, duration\: :ref:`float<class_float>`\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`SubtweenTweener<class_SubtweenTweener>` | :ref:`tween_subtween<class_Tween_method_tween_subtween>`\ (\ subtween\: :ref:`Tween<class_Tween>`\ ) |
- +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Signals
- -------
- .. _class_Tween_signal_finished:
- .. rst-class:: classref-signal
- **finished**\ (\ ) :ref:`🔗<class_Tween_signal_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>`).
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_signal_loop_finished:
- .. rst-class:: classref-signal
- **loop_finished**\ (\ loop_count\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Tween_signal_loop_finished>`
- 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 the final loop, use :ref:`finished<class_Tween_signal_finished>` instead for this case.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_signal_step_finished:
- .. rst-class:: classref-signal
- **step_finished**\ (\ idx\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Tween_signal_step_finished>`
- 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 in parallel.
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Enumerations
- ------------
- .. _enum_Tween_TweenProcessMode:
- .. rst-class:: classref-enumeration
- enum **TweenProcessMode**: :ref:`🔗<enum_Tween_TweenProcessMode>`
- .. _class_Tween_constant_TWEEN_PROCESS_PHYSICS:
- .. rst-class:: classref-enumeration-constant
- :ref:`TweenProcessMode<enum_Tween_TweenProcessMode>` **TWEEN_PROCESS_PHYSICS** = ``0``
- The **Tween** updates after each physics frame (see :ref:`Node._physics_process()<class_Node_private_method__physics_process>`).
- .. _class_Tween_constant_TWEEN_PROCESS_IDLE:
- .. rst-class:: classref-enumeration-constant
- :ref:`TweenProcessMode<enum_Tween_TweenProcessMode>` **TWEEN_PROCESS_IDLE** = ``1``
- The **Tween** updates after each process frame (see :ref:`Node._process()<class_Node_private_method__process>`).
- .. rst-class:: classref-item-separator
- ----
- .. _enum_Tween_TweenPauseMode:
- .. rst-class:: classref-enumeration
- enum **TweenPauseMode**: :ref:`🔗<enum_Tween_TweenPauseMode>`
- .. _class_Tween_constant_TWEEN_PAUSE_BOUND:
- .. rst-class:: classref-enumeration-constant
- :ref:`TweenPauseMode<enum_Tween_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>`.
- .. _class_Tween_constant_TWEEN_PAUSE_STOP:
- .. rst-class:: classref-enumeration-constant
- :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>` **TWEEN_PAUSE_STOP** = ``1``
- If :ref:`SceneTree<class_SceneTree>` is paused, the **Tween** will also pause.
- .. _class_Tween_constant_TWEEN_PAUSE_PROCESS:
- .. rst-class:: classref-enumeration-constant
- :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>` **TWEEN_PAUSE_PROCESS** = ``2``
- The **Tween** will process regardless of whether :ref:`SceneTree<class_SceneTree>` is paused.
- .. rst-class:: classref-item-separator
- ----
- .. _enum_Tween_TransitionType:
- .. rst-class:: classref-enumeration
- enum **TransitionType**: :ref:`🔗<enum_Tween_TransitionType>`
- .. _class_Tween_constant_TRANS_LINEAR:
- .. rst-class:: classref-enumeration-constant
- :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_LINEAR** = ``0``
- The animation is interpolated linearly.
- .. _class_Tween_constant_TRANS_SINE:
- .. rst-class:: classref-enumeration-constant
- :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_SINE** = ``1``
- The animation is interpolated using a sine function.
- .. _class_Tween_constant_TRANS_QUINT:
- .. rst-class:: classref-enumeration-constant
- :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_QUINT** = ``2``
- The animation is interpolated with a quintic (to the power of 5) function.
- .. _class_Tween_constant_TRANS_QUART:
- .. rst-class:: classref-enumeration-constant
- :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_QUART** = ``3``
- The animation is interpolated with a quartic (to the power of 4) function.
- .. _class_Tween_constant_TRANS_QUAD:
- .. rst-class:: classref-enumeration-constant
- :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_QUAD** = ``4``
- The animation is interpolated with a quadratic (to the power of 2) function.
- .. _class_Tween_constant_TRANS_EXPO:
- .. rst-class:: classref-enumeration-constant
- :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_EXPO** = ``5``
- The animation is interpolated with an exponential (to the power of x) function.
- .. _class_Tween_constant_TRANS_ELASTIC:
- .. rst-class:: classref-enumeration-constant
- :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_ELASTIC** = ``6``
- The animation is interpolated with elasticity, wiggling around the edges.
- .. _class_Tween_constant_TRANS_CUBIC:
- .. rst-class:: classref-enumeration-constant
- :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_CUBIC** = ``7``
- The animation is interpolated with a cubic (to the power of 3) function.
- .. _class_Tween_constant_TRANS_CIRC:
- .. rst-class:: classref-enumeration-constant
- :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_CIRC** = ``8``
- The animation is interpolated with a function using square roots.
- .. _class_Tween_constant_TRANS_BOUNCE:
- .. rst-class:: classref-enumeration-constant
- :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_BOUNCE** = ``9``
- The animation is interpolated by bouncing at the end.
- .. _class_Tween_constant_TRANS_BACK:
- .. rst-class:: classref-enumeration-constant
- :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_BACK** = ``10``
- The animation is interpolated backing out at ends.
- .. _class_Tween_constant_TRANS_SPRING:
- .. rst-class:: classref-enumeration-constant
- :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_SPRING** = ``11``
- The animation is interpolated like a spring towards the end.
- .. rst-class:: classref-item-separator
- ----
- .. _enum_Tween_EaseType:
- .. rst-class:: classref-enumeration
- enum **EaseType**: :ref:`🔗<enum_Tween_EaseType>`
- .. _class_Tween_constant_EASE_IN:
- .. rst-class:: classref-enumeration-constant
- :ref:`EaseType<enum_Tween_EaseType>` **EASE_IN** = ``0``
- The interpolation starts slowly and speeds up towards the end.
- .. _class_Tween_constant_EASE_OUT:
- .. rst-class:: classref-enumeration-constant
- :ref:`EaseType<enum_Tween_EaseType>` **EASE_OUT** = ``1``
- The interpolation starts quickly and slows down towards the end.
- .. _class_Tween_constant_EASE_IN_OUT:
- .. rst-class:: classref-enumeration-constant
- :ref:`EaseType<enum_Tween_EaseType>` **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.
- .. _class_Tween_constant_EASE_OUT_IN:
- .. rst-class:: classref-enumeration-constant
- :ref:`EaseType<enum_Tween_EaseType>` **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.
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Method Descriptions
- -------------------
- .. _class_Tween_method_bind_node:
- .. rst-class:: classref-method
- :ref:`Tween<class_Tween>` **bind_node**\ (\ node\: :ref:`Node<class_Node>`\ ) :ref:`🔗<class_Tween_method_bind_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>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_chain:
- .. rst-class:: classref-method
- :ref:`Tween<class_Tween>` **chain**\ (\ ) :ref:`🔗<class_Tween_method_chain>`
- Used to chain two :ref:`Tweener<class_Tweener>`\ s after :ref:`set_parallel()<class_Tween_method_set_parallel>` is called with ``true``.
- .. tabs::
- .. code-tab:: gdscript
- 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.
- .. code-tab:: csharp
- Tween tween = CreateTween().SetParallel(true);
- tween.TweenProperty(...);
- tween.TweenProperty(...); // Will run parallelly with above.
- tween.Chain().TweenProperty(...); // Will run after two above are finished.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_custom_step:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **custom_step**\ (\ delta\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Tween_method_custom_step>`
- Processes the **Tween** by the given ``delta`` value, in seconds. This is mostly useful for manual control when the **Tween** is paused. It can also be used to end the **Tween** animation immediately, by setting ``delta`` longer than the whole duration of the **Tween** animation.
- Returns ``true`` if the **Tween** still has :ref:`Tweener<class_Tweener>`\ s that haven't finished.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_get_loops_left:
- .. rst-class:: classref-method
- :ref:`int<class_int>` **get_loops_left**\ (\ ) |const| :ref:`🔗<class_Tween_method_get_loops_left>`
- Returns the number of remaining loops for this **Tween** (see :ref:`set_loops()<class_Tween_method_set_loops>`). A return value of ``-1`` indicates an infinitely looping **Tween**, and a return value of ``0`` indicates that the **Tween** has already finished.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_get_total_elapsed_time:
- .. rst-class:: classref-method
- :ref:`float<class_float>` **get_total_elapsed_time**\ (\ ) |const| :ref:`🔗<class_Tween_method_get_total_elapsed_time>`
- Returns the total time in seconds the **Tween** has been animating (i.e. the time since it started, not counting pauses etc.). The time is affected by :ref:`set_speed_scale()<class_Tween_method_set_speed_scale>`, and :ref:`stop()<class_Tween_method_stop>` will reset it to ``0``.
- \ **Note:** As it results from accumulating frame deltas, the time returned after the **Tween** has finished animating will be slightly greater than the actual **Tween** duration.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_interpolate_value:
- .. rst-class:: classref-method
- :ref:`Variant<class_Variant>` **interpolate_value**\ (\ initial_value\: :ref:`Variant<class_Variant>`, delta_value\: :ref:`Variant<class_Variant>`, elapsed_time\: :ref:`float<class_float>`, duration\: :ref:`float<class_float>`, trans_type\: :ref:`TransitionType<enum_Tween_TransitionType>`, ease_type\: :ref:`EaseType<enum_Tween_EaseType>`\ ) |static| :ref:`🔗<class_Tween_method_interpolate_value>`
- 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.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_is_running:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **is_running**\ (\ ) :ref:`🔗<class_Tween_method_is_running>`
- Returns whether the **Tween** is currently running, i.e. it wasn't paused and it's not finished.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_is_valid:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **is_valid**\ (\ ) :ref:`🔗<class_Tween_method_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**). A **Tween** might become invalid when it has finished tweening, is killed, or when created with ``Tween.new()``. Invalid **Tween**\ s can't have :ref:`Tweener<class_Tweener>`\ s appended.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_kill:
- .. rst-class:: classref-method
- |void| **kill**\ (\ ) :ref:`🔗<class_Tween_method_kill>`
- Aborts all tweening operations and invalidates the **Tween**.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_parallel:
- .. rst-class:: classref-method
- :ref:`Tween<class_Tween>` **parallel**\ (\ ) :ref:`🔗<class_Tween_method_parallel>`
- Makes the next :ref:`Tweener<class_Tweener>` run parallelly to the previous one.
- .. tabs::
- .. code-tab:: gdscript
- var tween = create_tween()
- tween.tween_property(...)
- tween.parallel().tween_property(...)
- tween.parallel().tween_property(...)
- .. code-tab:: csharp
- Tween tween = CreateTween();
- tween.TweenProperty(...);
- tween.Parallel().TweenProperty(...);
- tween.Parallel().TweenProperty(...);
- 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>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_pause:
- .. rst-class:: classref-method
- |void| **pause**\ (\ ) :ref:`🔗<class_Tween_method_pause>`
- Pauses the tweening. The animation can be resumed by using :ref:`play()<class_Tween_method_play>`.
- \ **Note:** If a Tween is paused and not bound to any node, it will exist indefinitely until manually started or invalidated. If you lose a reference to such Tween, you can retrieve it using :ref:`SceneTree.get_processed_tweens()<class_SceneTree_method_get_processed_tweens>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_play:
- .. rst-class:: classref-method
- |void| **play**\ (\ ) :ref:`🔗<class_Tween_method_play>`
- Resumes a paused or stopped **Tween**.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_set_ease:
- .. rst-class:: classref-method
- :ref:`Tween<class_Tween>` **set_ease**\ (\ ease\: :ref:`EaseType<enum_Tween_EaseType>`\ ) :ref:`🔗<class_Tween_method_set_ease>`
- Sets the default ease type for :ref:`PropertyTweener<class_PropertyTweener>`\ s and :ref:`MethodTweener<class_MethodTweener>`\ s appended after this method.
- Before this method is called, the default ease type is :ref:`EASE_IN_OUT<class_Tween_constant_EASE_IN_OUT>`.
- ::
- var tween = create_tween()
- tween.tween_property(self, "position", Vector2(300, 0), 0.5) # Uses EASE_IN_OUT.
- tween.set_ease(Tween.EASE_IN)
- tween.tween_property(self, "rotation_degrees", 45.0, 0.5) # Uses EASE_IN.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_set_ignore_time_scale:
- .. rst-class:: classref-method
- :ref:`Tween<class_Tween>` **set_ignore_time_scale**\ (\ ignore\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_Tween_method_set_ignore_time_scale>`
- If ``ignore`` is ``true``, the tween will ignore :ref:`Engine.time_scale<class_Engine_property_time_scale>` and update with the real, elapsed time. This affects all :ref:`Tweener<class_Tweener>`\ s and their delays. Default value is ``false``.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_set_loops:
- .. rst-class:: classref-method
- :ref:`Tween<class_Tween>` **set_loops**\ (\ loops\: :ref:`int<class_int>` = 0\ ) :ref:`🔗<class_Tween_method_set_loops>`
- 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 either it is killed with :ref:`kill()<class_Tween_method_kill>`, the **Tween**'s bound node is freed, 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. To prevent the game freezing, 0-duration looped animations (e.g. a single :ref:`CallbackTweener<class_CallbackTweener>` with no delay) are stopped after a small number of loops, which may produce unexpected results. If a **Tween**'s lifetime depends on some node, always use :ref:`bind_node()<class_Tween_method_bind_node>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_set_parallel:
- .. rst-class:: classref-method
- :ref:`Tween<class_Tween>` **set_parallel**\ (\ parallel\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_Tween_method_set_parallel>`
- If ``parallel`` is ``true``, the :ref:`Tweener<class_Tweener>`\ s appended after this method will by default run simultaneously, as opposed to sequentially.
- \ **Note:** Just like with :ref:`parallel()<class_Tween_method_parallel>`, the tweener added right before this method will also be part of the parallel step.
- ::
- tween.tween_property(self, "position", Vector2(300, 0), 0.5)
- tween.set_parallel()
- tween.tween_property(self, "modulate", Color.GREEN, 0.5) # Runs together with the position tweener.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_set_pause_mode:
- .. rst-class:: classref-method
- :ref:`Tween<class_Tween>` **set_pause_mode**\ (\ mode\: :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>`\ ) :ref:`🔗<class_Tween_method_set_pause_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>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_set_process_mode:
- .. rst-class:: classref-method
- :ref:`Tween<class_Tween>` **set_process_mode**\ (\ mode\: :ref:`TweenProcessMode<enum_Tween_TweenProcessMode>`\ ) :ref:`🔗<class_Tween_method_set_process_mode>`
- Determines whether the **Tween** should run after process frames (see :ref:`Node._process()<class_Node_private_method__process>`) or physics frames (see :ref:`Node._physics_process()<class_Node_private_method__physics_process>`).
- Default value is :ref:`TWEEN_PROCESS_IDLE<class_Tween_constant_TWEEN_PROCESS_IDLE>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_set_speed_scale:
- .. rst-class:: classref-method
- :ref:`Tween<class_Tween>` **set_speed_scale**\ (\ speed\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Tween_method_set_speed_scale>`
- Scales the speed of tweening. This affects all :ref:`Tweener<class_Tweener>`\ s and their delays.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_set_trans:
- .. rst-class:: classref-method
- :ref:`Tween<class_Tween>` **set_trans**\ (\ trans\: :ref:`TransitionType<enum_Tween_TransitionType>`\ ) :ref:`🔗<class_Tween_method_set_trans>`
- Sets the default transition type for :ref:`PropertyTweener<class_PropertyTweener>`\ s and :ref:`MethodTweener<class_MethodTweener>`\ s appended after this method.
- Before this method is called, the default transition type is :ref:`TRANS_LINEAR<class_Tween_constant_TRANS_LINEAR>`.
- ::
- var tween = create_tween()
- tween.tween_property(self, "position", Vector2(300, 0), 0.5) # Uses TRANS_LINEAR.
- tween.set_trans(Tween.TRANS_SINE)
- tween.tween_property(self, "rotation_degrees", 45.0, 0.5) # Uses TRANS_SINE.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_stop:
- .. rst-class:: classref-method
- |void| **stop**\ (\ ) :ref:`🔗<class_Tween_method_stop>`
- Stops the tweening and resets the **Tween** to its initial state. This will not remove any appended :ref:`Tweener<class_Tweener>`\ s.
- \ **Note:** This does *not* reset targets of :ref:`PropertyTweener<class_PropertyTweener>`\ s to their values when the **Tween** first started.
- ::
- var tween = create_tween()
-
- # Will move from 0 to 500 over 1 second.
- position.x = 0.0
- tween.tween_property(self, "position:x", 500, 1.0)
-
- # Will be at (about) 250 when the timer finishes.
- await get_tree().create_timer(0.5).timeout
-
- # Will now move from (about) 250 to 500 over 1 second,
- # thus at half the speed as before.
- tween.stop()
- tween.play()
- \ **Note:** If a Tween is stopped and not bound to any node, it will exist indefinitely until manually started or invalidated. If you lose a reference to such Tween, you can retrieve it using :ref:`SceneTree.get_processed_tweens()<class_SceneTree_method_get_processed_tweens>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_tween_callback:
- .. rst-class:: classref-method
- :ref:`CallbackTweener<class_CallbackTweener>` **tween_callback**\ (\ callback\: :ref:`Callable<class_Callable>`\ ) :ref:`🔗<class_Tween_method_tween_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:
- .. tabs::
- .. code-tab:: gdscript
- var tween = get_tree().create_tween().set_loops()
- tween.tween_callback(shoot).set_delay(1)
- .. code-tab:: csharp
- Tween tween = GetTree().CreateTween().SetLoops();
- tween.TweenCallback(Callable.From(Shoot)).SetDelay(1.0f);
- \ **Example:** Turning a sprite red and then blue, with 2 second delay:
- .. tabs::
- .. code-tab:: gdscript
- 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)
- .. code-tab:: csharp
- Tween tween = GetTree().CreateTween();
- Sprite2D sprite = GetNode<Sprite2D>("Sprite");
- tween.TweenCallback(Callable.From(() => sprite.Modulate = Colors.Red)).SetDelay(2.0f);
- tween.TweenCallback(Callable.From(() => sprite.Modulate = Colors.Blue)).SetDelay(2.0f);
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_tween_interval:
- .. rst-class:: classref-method
- :ref:`IntervalTweener<class_IntervalTweener>` **tween_interval**\ (\ time\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Tween_method_tween_interval>`
- Creates and appends an :ref:`IntervalTweener<class_IntervalTweener>`. This method can be used to create delays in the tween animation, as an alternative to 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:
- .. tabs::
- .. code-tab:: gdscript
- # ... some code
- await create_tween().tween_interval(2).finished
- # ... more code
- .. code-tab:: csharp
- // ... some code
- await ToSignal(CreateTween().TweenInterval(2.0f), Tween.SignalName.Finished);
- // ... more code
- \ **Example:** Creating an object that moves back and forth and jumps every few seconds:
- .. tabs::
- .. code-tab:: gdscript
- var tween = create_tween().set_loops()
- tween.tween_property($Sprite, "position:x", 200.0, 1).as_relative()
- tween.tween_callback(jump)
- tween.tween_interval(2)
- tween.tween_property($Sprite, "position:x", -200.0, 1).as_relative()
- tween.tween_callback(jump)
- tween.tween_interval(2)
- .. code-tab:: csharp
- Tween tween = CreateTween().SetLoops();
- tween.TweenProperty(GetNode("Sprite"), "position:x", 200.0f, 1.0f).AsRelative();
- tween.TweenCallback(Callable.From(Jump));
- tween.TweenInterval(2.0f);
- tween.TweenProperty(GetNode("Sprite"), "position:x", -200.0f, 1.0f).AsRelative();
- tween.TweenCallback(Callable.From(Jump));
- tween.TweenInterval(2.0f);
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_tween_method:
- .. rst-class:: classref-method
- :ref:`MethodTweener<class_MethodTweener>` **tween_method**\ (\ method\: :ref:`Callable<class_Callable>`, from\: :ref:`Variant<class_Variant>`, to\: :ref:`Variant<class_Variant>`, duration\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Tween_method_tween_method>`
- 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:
- .. tabs::
- .. code-tab:: gdscript
- 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.
- .. code-tab:: csharp
- Tween tween = CreateTween();
- tween.TweenMethod(Callable.From((Vector3 target) => LookAt(target, Vector3.Up)), new Vector3(-1.0f, 0.0f, -1.0f), new Vector3(1.0f, 0.0f, -1.0f), 1.0f); // Use lambdas to bind additional arguments for the call.
- \ **Example:** Setting the text of a :ref:`Label<class_Label>`, using an intermediate method and after a delay:
- .. tabs::
- .. code-tab:: gdscript
- 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)
- .. code-tab:: csharp
- public override void _Ready()
- {
- base._Ready();
-
- Tween tween = CreateTween();
- tween.TweenMethod(Callable.From<int>(SetLabelText), 0.0f, 10.0f, 1.0f).SetDelay(1.0f);
- }
-
- private void SetLabelText(int value)
- {
- GetNode<Label>("Label").Text = $"Counting {value}";
- }
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_tween_property:
- .. rst-class:: classref-method
- :ref:`PropertyTweener<class_PropertyTweener>` **tween_property**\ (\ object\: :ref:`Object<class_Object>`, property\: :ref:`NodePath<class_NodePath>`, final_val\: :ref:`Variant<class_Variant>`, duration\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Tween_method_tween_property>`
- 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 the property's value at the time the tweening of the :ref:`PropertyTweener<class_PropertyTweener>` starts.
- .. tabs::
- .. code-tab:: gdscript
- var tween = create_tween()
- tween.tween_property($Sprite, "position", Vector2(100, 200), 1)
- tween.tween_property($Sprite, "position", Vector2(200, 300), 1)
- .. code-tab:: csharp
- Tween tween = CreateTween();
- tween.TweenProperty(GetNode("Sprite"), "position", new Vector2(100.0f, 200.0f), 1.0f);
- tween.TweenProperty(GetNode("Sprite"), "position", new Vector2(200.0f, 300.0f), 1.0f);
- 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 an object twice from the same position, with different transition types:
- .. tabs::
- .. code-tab:: gdscript
- var tween = create_tween()
- tween.tween_property($Sprite, "position", Vector2.RIGHT * 300, 1).as_relative().set_trans(Tween.TRANS_SINE)
- tween.tween_property($Sprite, "position", Vector2.RIGHT * 300, 1).as_relative().from_current().set_trans(Tween.TRANS_EXPO)
- .. code-tab:: csharp
- Tween tween = CreateTween();
- tween.TweenProperty(GetNode("Sprite"), "position", Vector2.Right * 300.0f, 1.0f).AsRelative().SetTrans(Tween.TransitionType.Sine);
- tween.TweenProperty(GetNode("Sprite"), "position", Vector2.Right * 300.0f, 1.0f).AsRelative().FromCurrent().SetTrans(Tween.TransitionType.Expo);
- .. rst-class:: classref-item-separator
- ----
- .. _class_Tween_method_tween_subtween:
- .. rst-class:: classref-method
- :ref:`SubtweenTweener<class_SubtweenTweener>` **tween_subtween**\ (\ subtween\: :ref:`Tween<class_Tween>`\ ) :ref:`🔗<class_Tween_method_tween_subtween>`
- Creates and appends a :ref:`SubtweenTweener<class_SubtweenTweener>`. This method can be used to nest ``subtween`` within this **Tween**, allowing for the creation of more complex and composable sequences.
- ::
- # Subtween will rotate the object.
- var subtween = create_tween()
- subtween.tween_property(self, "rotation_degrees", 45.0, 1.0)
- subtween.tween_property(self, "rotation_degrees", 0.0, 1.0)
-
- # Parent tween will execute the subtween as one of its steps.
- var tween = create_tween()
- tween.tween_property(self, "position:x", 500, 3.0)
- tween.tween_subtween(subtween)
- tween.tween_property(self, "position:x", 300, 2.0)
- \ **Note:** The methods :ref:`pause()<class_Tween_method_pause>`, :ref:`stop()<class_Tween_method_stop>`, and :ref:`set_loops()<class_Tween_method_set_loops>` can cause the parent **Tween** to get stuck on the subtween step; see the documentation for those methods for more information.
- \ **Note:** The pause and process modes set by :ref:`set_pause_mode()<class_Tween_method_set_pause_mode>` and :ref:`set_process_mode()<class_Tween_method_set_process_mode>` on ``subtween`` will be overridden by the parent **Tween**'s settings.
- .. |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.)`
- .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
- .. |void| replace:: :abbr:`void (No return value.)`
|