class_tween.rst 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Tween.xml.
  6. .. _class_Tween:
  7. Tween
  8. =====
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Lightweight object used for general-purpose animation via script, using :ref:`Tweener<class_Tweener>`\ s.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. 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.
  15. \ **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.
  16. 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.
  17. 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>`:
  18. .. tabs::
  19. .. code-tab:: gdscript
  20. var tween = get_tree().create_tween()
  21. tween.tween_property($Sprite, "modulate", Color.RED, 1)
  22. tween.tween_property($Sprite, "scale", Vector2(), 1)
  23. tween.tween_callback($Sprite.queue_free)
  24. .. code-tab:: csharp
  25. Tween tween = GetTree().CreateTween();
  26. tween.TweenProperty(GetNode("Sprite"), "modulate", Colors.Red, 1.0f);
  27. tween.TweenProperty(GetNode("Sprite"), "scale", Vector2.Zero, 1.0f);
  28. tween.TweenCallback(Callable.From(GetNode("Sprite").QueueFree));
  29. 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>`.
  30. 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>`:
  31. .. tabs::
  32. .. code-tab:: gdscript
  33. var tween = get_tree().create_tween()
  34. tween.tween_property($Sprite, "modulate", Color.RED, 1).set_trans(Tween.TRANS_SINE)
  35. tween.tween_property($Sprite, "scale", Vector2(), 1).set_trans(Tween.TRANS_BOUNCE)
  36. tween.tween_callback($Sprite.queue_free)
  37. .. code-tab:: csharp
  38. Tween tween = GetTree().CreateTween();
  39. tween.TweenProperty(GetNode("Sprite"), "modulate", Colors.Red, 1.0f).SetTrans(Tween.TransitionType.Sine);
  40. tween.TweenProperty(GetNode("Sprite"), "scale", Vector2.Zero, 1.0f).SetTrans(Tween.TransitionType.Bounce);
  41. tween.TweenCallback(Callable.From(GetNode("Sprite").QueueFree));
  42. 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:
  43. .. tabs::
  44. .. code-tab:: gdscript
  45. var tween = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_ELASTIC)
  46. tween.tween_property($Sprite, "modulate", Color.RED, 1)
  47. tween.tween_property($Sprite, "scale", Vector2(), 1)
  48. tween.tween_callback($Sprite.queue_free)
  49. .. code-tab:: csharp
  50. var tween = GetTree().CreateTween().BindNode(this).SetTrans(Tween.TransitionType.Elastic);
  51. tween.TweenProperty(GetNode("Sprite"), "modulate", Colors.Red, 1.0f);
  52. tween.TweenProperty(GetNode("Sprite"), "scale", Vector2.Zero, 1.0f);
  53. tween.TweenCallback(Callable.From(GetNode("Sprite").QueueFree));
  54. Another interesting use for **Tween**\ s is animating arbitrary sets of objects:
  55. .. tabs::
  56. .. code-tab:: gdscript
  57. var tween = create_tween()
  58. for sprite in get_children():
  59. tween.tween_property(sprite, "position", Vector2(0, 0), 1)
  60. .. code-tab:: csharp
  61. Tween tween = CreateTween();
  62. foreach (Node sprite in GetChildren())
  63. tween.TweenProperty(sprite, "position", Vector2.Zero, 1.0f);
  64. In the example above, all children of a node are moved one after another to position (0, 0).
  65. 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:
  66. .. tabs::
  67. .. code-tab:: gdscript
  68. var tween
  69. func animate():
  70. if tween:
  71. tween.kill() # Abort the previous animation.
  72. tween = create_tween()
  73. .. code-tab:: csharp
  74. private Tween _tween;
  75. public void Animate()
  76. {
  77. if (_tween != null)
  78. _tween.Kill(); // Abort the previous animation
  79. _tween = CreateTween();
  80. }
  81. 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.
  82. \ `Tween easing and transition types cheatsheet <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/tween_cheatsheet.webp>`__\
  83. \ **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.
  84. \ **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>`).
  85. .. rst-class:: classref-reftable-group
  86. Methods
  87. -------
  88. .. table::
  89. :widths: auto
  90. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`Tween<class_Tween>` | :ref:`bind_node<class_Tween_method_bind_node>`\ (\ node\: :ref:`Node<class_Node>`\ ) |
  92. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`Tween<class_Tween>` | :ref:`chain<class_Tween_method_chain>`\ (\ ) |
  94. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`bool<class_bool>` | :ref:`custom_step<class_Tween_method_custom_step>`\ (\ delta\: :ref:`float<class_float>`\ ) |
  96. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :ref:`int<class_int>` | :ref:`get_loops_left<class_Tween_method_get_loops_left>`\ (\ ) |const| |
  98. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`float<class_float>` | :ref:`get_total_elapsed_time<class_Tween_method_get_total_elapsed_time>`\ (\ ) |const| |
  100. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | :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| |
  102. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | :ref:`bool<class_bool>` | :ref:`is_running<class_Tween_method_is_running>`\ (\ ) |
  104. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | :ref:`bool<class_bool>` | :ref:`is_valid<class_Tween_method_is_valid>`\ (\ ) |
  106. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | |void| | :ref:`kill<class_Tween_method_kill>`\ (\ ) |
  108. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. | :ref:`Tween<class_Tween>` | :ref:`parallel<class_Tween_method_parallel>`\ (\ ) |
  110. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  111. | |void| | :ref:`pause<class_Tween_method_pause>`\ (\ ) |
  112. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  113. | |void| | :ref:`play<class_Tween_method_play>`\ (\ ) |
  114. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  115. | :ref:`Tween<class_Tween>` | :ref:`set_ease<class_Tween_method_set_ease>`\ (\ ease\: :ref:`EaseType<enum_Tween_EaseType>`\ ) |
  116. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  117. | :ref:`Tween<class_Tween>` | :ref:`set_ignore_time_scale<class_Tween_method_set_ignore_time_scale>`\ (\ ignore\: :ref:`bool<class_bool>` = true\ ) |
  118. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  119. | :ref:`Tween<class_Tween>` | :ref:`set_loops<class_Tween_method_set_loops>`\ (\ loops\: :ref:`int<class_int>` = 0\ ) |
  120. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  121. | :ref:`Tween<class_Tween>` | :ref:`set_parallel<class_Tween_method_set_parallel>`\ (\ parallel\: :ref:`bool<class_bool>` = true\ ) |
  122. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  123. | :ref:`Tween<class_Tween>` | :ref:`set_pause_mode<class_Tween_method_set_pause_mode>`\ (\ mode\: :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>`\ ) |
  124. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  125. | :ref:`Tween<class_Tween>` | :ref:`set_process_mode<class_Tween_method_set_process_mode>`\ (\ mode\: :ref:`TweenProcessMode<enum_Tween_TweenProcessMode>`\ ) |
  126. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  127. | :ref:`Tween<class_Tween>` | :ref:`set_speed_scale<class_Tween_method_set_speed_scale>`\ (\ speed\: :ref:`float<class_float>`\ ) |
  128. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  129. | :ref:`Tween<class_Tween>` | :ref:`set_trans<class_Tween_method_set_trans>`\ (\ trans\: :ref:`TransitionType<enum_Tween_TransitionType>`\ ) |
  130. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  131. | |void| | :ref:`stop<class_Tween_method_stop>`\ (\ ) |
  132. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  133. | :ref:`CallbackTweener<class_CallbackTweener>` | :ref:`tween_callback<class_Tween_method_tween_callback>`\ (\ callback\: :ref:`Callable<class_Callable>`\ ) |
  134. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  135. | :ref:`IntervalTweener<class_IntervalTweener>` | :ref:`tween_interval<class_Tween_method_tween_interval>`\ (\ time\: :ref:`float<class_float>`\ ) |
  136. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  137. | :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>`\ ) |
  138. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  139. | :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>`\ ) |
  140. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  141. .. rst-class:: classref-section-separator
  142. ----
  143. .. rst-class:: classref-descriptions-group
  144. Signals
  145. -------
  146. .. _class_Tween_signal_finished:
  147. .. rst-class:: classref-signal
  148. **finished**\ (\ ) :ref:`🔗<class_Tween_signal_finished>`
  149. 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>`).
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. _class_Tween_signal_loop_finished:
  153. .. rst-class:: classref-signal
  154. **loop_finished**\ (\ loop_count\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Tween_signal_loop_finished>`
  155. 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.
  156. .. rst-class:: classref-item-separator
  157. ----
  158. .. _class_Tween_signal_step_finished:
  159. .. rst-class:: classref-signal
  160. **step_finished**\ (\ idx\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Tween_signal_step_finished>`
  161. 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.
  162. .. rst-class:: classref-section-separator
  163. ----
  164. .. rst-class:: classref-descriptions-group
  165. Enumerations
  166. ------------
  167. .. _enum_Tween_TweenProcessMode:
  168. .. rst-class:: classref-enumeration
  169. enum **TweenProcessMode**: :ref:`🔗<enum_Tween_TweenProcessMode>`
  170. .. _class_Tween_constant_TWEEN_PROCESS_PHYSICS:
  171. .. rst-class:: classref-enumeration-constant
  172. :ref:`TweenProcessMode<enum_Tween_TweenProcessMode>` **TWEEN_PROCESS_PHYSICS** = ``0``
  173. The **Tween** updates after each physics frame (see :ref:`Node._physics_process<class_Node_private_method__physics_process>`).
  174. .. _class_Tween_constant_TWEEN_PROCESS_IDLE:
  175. .. rst-class:: classref-enumeration-constant
  176. :ref:`TweenProcessMode<enum_Tween_TweenProcessMode>` **TWEEN_PROCESS_IDLE** = ``1``
  177. The **Tween** updates after each process frame (see :ref:`Node._process<class_Node_private_method__process>`).
  178. .. rst-class:: classref-item-separator
  179. ----
  180. .. _enum_Tween_TweenPauseMode:
  181. .. rst-class:: classref-enumeration
  182. enum **TweenPauseMode**: :ref:`🔗<enum_Tween_TweenPauseMode>`
  183. .. _class_Tween_constant_TWEEN_PAUSE_BOUND:
  184. .. rst-class:: classref-enumeration-constant
  185. :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>` **TWEEN_PAUSE_BOUND** = ``0``
  186. 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>`.
  187. .. _class_Tween_constant_TWEEN_PAUSE_STOP:
  188. .. rst-class:: classref-enumeration-constant
  189. :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>` **TWEEN_PAUSE_STOP** = ``1``
  190. If :ref:`SceneTree<class_SceneTree>` is paused, the **Tween** will also pause.
  191. .. _class_Tween_constant_TWEEN_PAUSE_PROCESS:
  192. .. rst-class:: classref-enumeration-constant
  193. :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>` **TWEEN_PAUSE_PROCESS** = ``2``
  194. The **Tween** will process regardless of whether :ref:`SceneTree<class_SceneTree>` is paused.
  195. .. rst-class:: classref-item-separator
  196. ----
  197. .. _enum_Tween_TransitionType:
  198. .. rst-class:: classref-enumeration
  199. enum **TransitionType**: :ref:`🔗<enum_Tween_TransitionType>`
  200. .. _class_Tween_constant_TRANS_LINEAR:
  201. .. rst-class:: classref-enumeration-constant
  202. :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_LINEAR** = ``0``
  203. The animation is interpolated linearly.
  204. .. _class_Tween_constant_TRANS_SINE:
  205. .. rst-class:: classref-enumeration-constant
  206. :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_SINE** = ``1``
  207. The animation is interpolated using a sine function.
  208. .. _class_Tween_constant_TRANS_QUINT:
  209. .. rst-class:: classref-enumeration-constant
  210. :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_QUINT** = ``2``
  211. The animation is interpolated with a quintic (to the power of 5) function.
  212. .. _class_Tween_constant_TRANS_QUART:
  213. .. rst-class:: classref-enumeration-constant
  214. :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_QUART** = ``3``
  215. The animation is interpolated with a quartic (to the power of 4) function.
  216. .. _class_Tween_constant_TRANS_QUAD:
  217. .. rst-class:: classref-enumeration-constant
  218. :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_QUAD** = ``4``
  219. The animation is interpolated with a quadratic (to the power of 2) function.
  220. .. _class_Tween_constant_TRANS_EXPO:
  221. .. rst-class:: classref-enumeration-constant
  222. :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_EXPO** = ``5``
  223. The animation is interpolated with an exponential (to the power of x) function.
  224. .. _class_Tween_constant_TRANS_ELASTIC:
  225. .. rst-class:: classref-enumeration-constant
  226. :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_ELASTIC** = ``6``
  227. The animation is interpolated with elasticity, wiggling around the edges.
  228. .. _class_Tween_constant_TRANS_CUBIC:
  229. .. rst-class:: classref-enumeration-constant
  230. :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_CUBIC** = ``7``
  231. The animation is interpolated with a cubic (to the power of 3) function.
  232. .. _class_Tween_constant_TRANS_CIRC:
  233. .. rst-class:: classref-enumeration-constant
  234. :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_CIRC** = ``8``
  235. The animation is interpolated with a function using square roots.
  236. .. _class_Tween_constant_TRANS_BOUNCE:
  237. .. rst-class:: classref-enumeration-constant
  238. :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_BOUNCE** = ``9``
  239. The animation is interpolated by bouncing at the end.
  240. .. _class_Tween_constant_TRANS_BACK:
  241. .. rst-class:: classref-enumeration-constant
  242. :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_BACK** = ``10``
  243. The animation is interpolated backing out at ends.
  244. .. _class_Tween_constant_TRANS_SPRING:
  245. .. rst-class:: classref-enumeration-constant
  246. :ref:`TransitionType<enum_Tween_TransitionType>` **TRANS_SPRING** = ``11``
  247. The animation is interpolated like a spring towards the end.
  248. .. rst-class:: classref-item-separator
  249. ----
  250. .. _enum_Tween_EaseType:
  251. .. rst-class:: classref-enumeration
  252. enum **EaseType**: :ref:`🔗<enum_Tween_EaseType>`
  253. .. _class_Tween_constant_EASE_IN:
  254. .. rst-class:: classref-enumeration-constant
  255. :ref:`EaseType<enum_Tween_EaseType>` **EASE_IN** = ``0``
  256. The interpolation starts slowly and speeds up towards the end.
  257. .. _class_Tween_constant_EASE_OUT:
  258. .. rst-class:: classref-enumeration-constant
  259. :ref:`EaseType<enum_Tween_EaseType>` **EASE_OUT** = ``1``
  260. The interpolation starts quickly and slows down towards the end.
  261. .. _class_Tween_constant_EASE_IN_OUT:
  262. .. rst-class:: classref-enumeration-constant
  263. :ref:`EaseType<enum_Tween_EaseType>` **EASE_IN_OUT** = ``2``
  264. 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.
  265. .. _class_Tween_constant_EASE_OUT_IN:
  266. .. rst-class:: classref-enumeration-constant
  267. :ref:`EaseType<enum_Tween_EaseType>` **EASE_OUT_IN** = ``3``
  268. 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.
  269. .. rst-class:: classref-section-separator
  270. ----
  271. .. rst-class:: classref-descriptions-group
  272. Method Descriptions
  273. -------------------
  274. .. _class_Tween_method_bind_node:
  275. .. rst-class:: classref-method
  276. :ref:`Tween<class_Tween>` **bind_node**\ (\ node\: :ref:`Node<class_Node>`\ ) :ref:`🔗<class_Tween_method_bind_node>`
  277. 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.
  278. For a shorter way to create and bind a **Tween**, you can use :ref:`Node.create_tween<class_Node_method_create_tween>`.
  279. .. rst-class:: classref-item-separator
  280. ----
  281. .. _class_Tween_method_chain:
  282. .. rst-class:: classref-method
  283. :ref:`Tween<class_Tween>` **chain**\ (\ ) :ref:`🔗<class_Tween_method_chain>`
  284. Used to chain two :ref:`Tweener<class_Tweener>`\ s after :ref:`set_parallel<class_Tween_method_set_parallel>` is called with ``true``.
  285. .. tabs::
  286. .. code-tab:: gdscript
  287. var tween = create_tween().set_parallel(true)
  288. tween.tween_property(...)
  289. tween.tween_property(...) # Will run parallelly with above.
  290. tween.chain().tween_property(...) # Will run after two above are finished.
  291. .. code-tab:: csharp
  292. Tween tween = CreateTween().SetParallel(true);
  293. tween.TweenProperty(...);
  294. tween.TweenProperty(...); // Will run parallelly with above.
  295. tween.Chain().TweenProperty(...); // Will run after two above are finished.
  296. .. rst-class:: classref-item-separator
  297. ----
  298. .. _class_Tween_method_custom_step:
  299. .. rst-class:: classref-method
  300. :ref:`bool<class_bool>` **custom_step**\ (\ delta\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Tween_method_custom_step>`
  301. 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.
  302. Returns ``true`` if the **Tween** still has :ref:`Tweener<class_Tweener>`\ s that haven't finished.
  303. .. rst-class:: classref-item-separator
  304. ----
  305. .. _class_Tween_method_get_loops_left:
  306. .. rst-class:: classref-method
  307. :ref:`int<class_int>` **get_loops_left**\ (\ ) |const| :ref:`🔗<class_Tween_method_get_loops_left>`
  308. 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.
  309. .. rst-class:: classref-item-separator
  310. ----
  311. .. _class_Tween_method_get_total_elapsed_time:
  312. .. rst-class:: classref-method
  313. :ref:`float<class_float>` **get_total_elapsed_time**\ (\ ) |const| :ref:`🔗<class_Tween_method_get_total_elapsed_time>`
  314. 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``.
  315. \ **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.
  316. .. rst-class:: classref-item-separator
  317. ----
  318. .. _class_Tween_method_interpolate_value:
  319. .. rst-class:: classref-method
  320. :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>`
  321. 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.
  322. \ ``initial_value`` is the starting value of the interpolation.
  323. \ ``delta_value`` is the change of the value in the interpolation, i.e. it's equal to ``final_value - initial_value``.
  324. \ ``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.
  325. \ ``duration`` is the total time of the interpolation.
  326. \ **Note:** If ``duration`` is equal to ``0``, the method will always return the final value, regardless of ``elapsed_time`` provided.
  327. .. rst-class:: classref-item-separator
  328. ----
  329. .. _class_Tween_method_is_running:
  330. .. rst-class:: classref-method
  331. :ref:`bool<class_bool>` **is_running**\ (\ ) :ref:`🔗<class_Tween_method_is_running>`
  332. Returns whether the **Tween** is currently running, i.e. it wasn't paused and it's not finished.
  333. .. rst-class:: classref-item-separator
  334. ----
  335. .. _class_Tween_method_is_valid:
  336. .. rst-class:: classref-method
  337. :ref:`bool<class_bool>` **is_valid**\ (\ ) :ref:`🔗<class_Tween_method_is_valid>`
  338. 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.
  339. .. rst-class:: classref-item-separator
  340. ----
  341. .. _class_Tween_method_kill:
  342. .. rst-class:: classref-method
  343. |void| **kill**\ (\ ) :ref:`🔗<class_Tween_method_kill>`
  344. Aborts all tweening operations and invalidates the **Tween**.
  345. .. rst-class:: classref-item-separator
  346. ----
  347. .. _class_Tween_method_parallel:
  348. .. rst-class:: classref-method
  349. :ref:`Tween<class_Tween>` **parallel**\ (\ ) :ref:`🔗<class_Tween_method_parallel>`
  350. Makes the next :ref:`Tweener<class_Tweener>` run parallelly to the previous one.
  351. .. tabs::
  352. .. code-tab:: gdscript
  353. var tween = create_tween()
  354. tween.tween_property(...)
  355. tween.parallel().tween_property(...)
  356. tween.parallel().tween_property(...)
  357. .. code-tab:: csharp
  358. Tween tween = CreateTween();
  359. tween.TweenProperty(...);
  360. tween.Parallel().TweenProperty(...);
  361. tween.Parallel().TweenProperty(...);
  362. All :ref:`Tweener<class_Tweener>`\ s in the example will run at the same time.
  363. You can make the **Tween** parallel by default by using :ref:`set_parallel<class_Tween_method_set_parallel>`.
  364. .. rst-class:: classref-item-separator
  365. ----
  366. .. _class_Tween_method_pause:
  367. .. rst-class:: classref-method
  368. |void| **pause**\ (\ ) :ref:`🔗<class_Tween_method_pause>`
  369. Pauses the tweening. The animation can be resumed by using :ref:`play<class_Tween_method_play>`.
  370. \ **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>`.
  371. .. rst-class:: classref-item-separator
  372. ----
  373. .. _class_Tween_method_play:
  374. .. rst-class:: classref-method
  375. |void| **play**\ (\ ) :ref:`🔗<class_Tween_method_play>`
  376. Resumes a paused or stopped **Tween**.
  377. .. rst-class:: classref-item-separator
  378. ----
  379. .. _class_Tween_method_set_ease:
  380. .. rst-class:: classref-method
  381. :ref:`Tween<class_Tween>` **set_ease**\ (\ ease\: :ref:`EaseType<enum_Tween_EaseType>`\ ) :ref:`🔗<class_Tween_method_set_ease>`
  382. Sets the default ease type for :ref:`PropertyTweener<class_PropertyTweener>`\ s and :ref:`MethodTweener<class_MethodTweener>`\ s appended after this method.
  383. Before this method is called, the default ease type is :ref:`EASE_IN_OUT<class_Tween_constant_EASE_IN_OUT>`.
  384. ::
  385. var tween = create_tween()
  386. tween.tween_property(self, "position", Vector2(300, 0), 0.5) # Uses EASE_IN_OUT.
  387. tween.set_ease(Tween.EASE_IN)
  388. tween.tween_property(self, "rotation_degrees", 45.0, 0.5) # Uses EASE_IN.
  389. .. rst-class:: classref-item-separator
  390. ----
  391. .. _class_Tween_method_set_ignore_time_scale:
  392. .. rst-class:: classref-method
  393. :ref:`Tween<class_Tween>` **set_ignore_time_scale**\ (\ ignore\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_Tween_method_set_ignore_time_scale>`
  394. 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``.
  395. .. rst-class:: classref-item-separator
  396. ----
  397. .. _class_Tween_method_set_loops:
  398. .. rst-class:: classref-method
  399. :ref:`Tween<class_Tween>` **set_loops**\ (\ loops\: :ref:`int<class_int>` = 0\ ) :ref:`🔗<class_Tween_method_set_loops>`
  400. Sets the number of times the tweening sequence will be repeated, i.e. ``set_loops(2)`` will run the animation twice.
  401. 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).
  402. \ **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>`.
  403. .. rst-class:: classref-item-separator
  404. ----
  405. .. _class_Tween_method_set_parallel:
  406. .. rst-class:: classref-method
  407. :ref:`Tween<class_Tween>` **set_parallel**\ (\ parallel\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_Tween_method_set_parallel>`
  408. If ``parallel`` is ``true``, the :ref:`Tweener<class_Tweener>`\ s appended after this method will by default run simultaneously, as opposed to sequentially.
  409. \ **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.
  410. ::
  411. tween.tween_property(self, "position", Vector2(300, 0), 0.5)
  412. tween.set_parallel()
  413. tween.tween_property(self, "modulate", Color.GREEN, 0.5) # Runs together with the position tweener.
  414. .. rst-class:: classref-item-separator
  415. ----
  416. .. _class_Tween_method_set_pause_mode:
  417. .. rst-class:: classref-method
  418. :ref:`Tween<class_Tween>` **set_pause_mode**\ (\ mode\: :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>`\ ) :ref:`🔗<class_Tween_method_set_pause_mode>`
  419. Determines the behavior of the **Tween** when the :ref:`SceneTree<class_SceneTree>` is paused. Check :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>` for options.
  420. Default value is :ref:`TWEEN_PAUSE_BOUND<class_Tween_constant_TWEEN_PAUSE_BOUND>`.
  421. .. rst-class:: classref-item-separator
  422. ----
  423. .. _class_Tween_method_set_process_mode:
  424. .. rst-class:: classref-method
  425. :ref:`Tween<class_Tween>` **set_process_mode**\ (\ mode\: :ref:`TweenProcessMode<enum_Tween_TweenProcessMode>`\ ) :ref:`🔗<class_Tween_method_set_process_mode>`
  426. 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>`).
  427. Default value is :ref:`TWEEN_PROCESS_IDLE<class_Tween_constant_TWEEN_PROCESS_IDLE>`.
  428. .. rst-class:: classref-item-separator
  429. ----
  430. .. _class_Tween_method_set_speed_scale:
  431. .. rst-class:: classref-method
  432. :ref:`Tween<class_Tween>` **set_speed_scale**\ (\ speed\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Tween_method_set_speed_scale>`
  433. Scales the speed of tweening. This affects all :ref:`Tweener<class_Tweener>`\ s and their delays.
  434. .. rst-class:: classref-item-separator
  435. ----
  436. .. _class_Tween_method_set_trans:
  437. .. rst-class:: classref-method
  438. :ref:`Tween<class_Tween>` **set_trans**\ (\ trans\: :ref:`TransitionType<enum_Tween_TransitionType>`\ ) :ref:`🔗<class_Tween_method_set_trans>`
  439. Sets the default transition type for :ref:`PropertyTweener<class_PropertyTweener>`\ s and :ref:`MethodTweener<class_MethodTweener>`\ s appended after this method.
  440. Before this method is called, the default transition type is :ref:`TRANS_LINEAR<class_Tween_constant_TRANS_LINEAR>`.
  441. ::
  442. var tween = create_tween()
  443. tween.tween_property(self, "position", Vector2(300, 0), 0.5) # Uses TRANS_LINEAR.
  444. tween.set_trans(Tween.TRANS_SINE)
  445. tween.tween_property(self, "rotation_degrees", 45.0, 0.5) # Uses TRANS_SINE.
  446. .. rst-class:: classref-item-separator
  447. ----
  448. .. _class_Tween_method_stop:
  449. .. rst-class:: classref-method
  450. |void| **stop**\ (\ ) :ref:`🔗<class_Tween_method_stop>`
  451. Stops the tweening and resets the **Tween** to its initial state. This will not remove any appended :ref:`Tweener<class_Tweener>`\ s.
  452. \ **Note:** This does *not* reset targets of :ref:`PropertyTweener<class_PropertyTweener>`\ s to their values when the **Tween** first started.
  453. ::
  454. var tween = create_tween()
  455. # Will move from 0 to 500 over 1 second.
  456. position.x = 0.0
  457. tween.tween_property(self, "position:x", 500, 1.0)
  458. # Will be at (about) 250 when the timer finishes.
  459. await get_tree().create_timer(0.5).timeout
  460. # Will now move from (about) 250 to 500 over 1 second,
  461. # thus at half the speed as before.
  462. tween.stop()
  463. tween.play()
  464. \ **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>`.
  465. .. rst-class:: classref-item-separator
  466. ----
  467. .. _class_Tween_method_tween_callback:
  468. .. rst-class:: classref-method
  469. :ref:`CallbackTweener<class_CallbackTweener>` **tween_callback**\ (\ callback\: :ref:`Callable<class_Callable>`\ ) :ref:`🔗<class_Tween_method_tween_callback>`
  470. 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.
  471. \ **Example:** Object that keeps shooting every 1 second:
  472. .. tabs::
  473. .. code-tab:: gdscript
  474. var tween = get_tree().create_tween().set_loops()
  475. tween.tween_callback(shoot).set_delay(1)
  476. .. code-tab:: csharp
  477. Tween tween = GetTree().CreateTween().SetLoops();
  478. tween.TweenCallback(Callable.From(Shoot)).SetDelay(1.0f);
  479. \ **Example:** Turning a sprite red and then blue, with 2 second delay:
  480. .. tabs::
  481. .. code-tab:: gdscript
  482. var tween = get_tree().create_tween()
  483. tween.tween_callback($Sprite.set_modulate.bind(Color.RED)).set_delay(2)
  484. tween.tween_callback($Sprite.set_modulate.bind(Color.BLUE)).set_delay(2)
  485. .. code-tab:: csharp
  486. Tween tween = GetTree().CreateTween();
  487. Sprite2D sprite = GetNode<Sprite2D>("Sprite");
  488. tween.TweenCallback(Callable.From(() => sprite.Modulate = Colors.Red)).SetDelay(2.0f);
  489. tween.TweenCallback(Callable.From(() => sprite.Modulate = Colors.Blue)).SetDelay(2.0f);
  490. .. rst-class:: classref-item-separator
  491. ----
  492. .. _class_Tween_method_tween_interval:
  493. .. rst-class:: classref-method
  494. :ref:`IntervalTweener<class_IntervalTweener>` **tween_interval**\ (\ time\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Tween_method_tween_interval>`
  495. 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.
  496. \ **Example:** Creating an interval in code execution:
  497. .. tabs::
  498. .. code-tab:: gdscript
  499. # ... some code
  500. await create_tween().tween_interval(2).finished
  501. # ... more code
  502. .. code-tab:: csharp
  503. // ... some code
  504. await ToSignal(CreateTween().TweenInterval(2.0f), Tween.SignalName.Finished);
  505. // ... more code
  506. \ **Example:** Creating an object that moves back and forth and jumps every few seconds:
  507. .. tabs::
  508. .. code-tab:: gdscript
  509. var tween = create_tween().set_loops()
  510. tween.tween_property($Sprite, "position:x", 200.0, 1).as_relative()
  511. tween.tween_callback(jump)
  512. tween.tween_interval(2)
  513. tween.tween_property($Sprite, "position:x", -200.0, 1).as_relative()
  514. tween.tween_callback(jump)
  515. tween.tween_interval(2)
  516. .. code-tab:: csharp
  517. Tween tween = CreateTween().SetLoops();
  518. tween.TweenProperty(GetNode("Sprite"), "position:x", 200.0f, 1.0f).AsRelative();
  519. tween.TweenCallback(Callable.From(Jump));
  520. tween.TweenInterval(2.0f);
  521. tween.TweenProperty(GetNode("Sprite"), "position:x", -200.0f, 1.0f).AsRelative();
  522. tween.TweenCallback(Callable.From(Jump));
  523. tween.TweenInterval(2.0f);
  524. .. rst-class:: classref-item-separator
  525. ----
  526. .. _class_Tween_method_tween_method:
  527. .. rst-class:: classref-method
  528. :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>`
  529. 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.
  530. \ **Example:** Making a 3D object look from one point to another point:
  531. .. tabs::
  532. .. code-tab:: gdscript
  533. var tween = create_tween()
  534. 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.
  535. .. code-tab:: csharp
  536. Tween tween = CreateTween();
  537. 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.
  538. \ **Example:** Setting the text of a :ref:`Label<class_Label>`, using an intermediate method and after a delay:
  539. .. tabs::
  540. .. code-tab:: gdscript
  541. func _ready():
  542. var tween = create_tween()
  543. tween.tween_method(set_label_text, 0, 10, 1).set_delay(1)
  544. func set_label_text(value: int):
  545. $Label.text = "Counting " + str(value)
  546. .. code-tab:: csharp
  547. public override void _Ready()
  548. {
  549. base._Ready();
  550. Tween tween = CreateTween();
  551. tween.TweenMethod(Callable.From<int>(SetLabelText), 0.0f, 10.0f, 1.0f).SetDelay(1.0f);
  552. }
  553. private void SetLabelText(int value)
  554. {
  555. GetNode<Label>("Label").Text = $"Counting {value}";
  556. }
  557. .. rst-class:: classref-item-separator
  558. ----
  559. .. _class_Tween_method_tween_property:
  560. .. rst-class:: classref-method
  561. :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>`
  562. 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.
  563. .. tabs::
  564. .. code-tab:: gdscript
  565. var tween = create_tween()
  566. tween.tween_property($Sprite, "position", Vector2(100, 200), 1)
  567. tween.tween_property($Sprite, "position", Vector2(200, 300), 1)
  568. .. code-tab:: csharp
  569. Tween tween = CreateTween();
  570. tween.TweenProperty(GetNode("Sprite"), "position", new Vector2(100.0f, 200.0f), 1.0f);
  571. tween.TweenProperty(GetNode("Sprite"), "position", new Vector2(200.0f, 300.0f), 1.0f);
  572. 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.
  573. \ **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.
  574. \ **Example:** Moving an object twice from the same position, with different transition types:
  575. .. tabs::
  576. .. code-tab:: gdscript
  577. var tween = create_tween()
  578. tween.tween_property($Sprite, "position", Vector2.RIGHT * 300, 1).as_relative().set_trans(Tween.TRANS_SINE)
  579. tween.tween_property($Sprite, "position", Vector2.RIGHT * 300, 1).as_relative().from_current().set_trans(Tween.TRANS_EXPO)
  580. .. code-tab:: csharp
  581. Tween tween = CreateTween();
  582. tween.TweenProperty(GetNode("Sprite"), "position", Vector2.Right * 300.0f, 1.0f).AsRelative().SetTrans(Tween.TransitionType.Sine);
  583. tween.TweenProperty(GetNode("Sprite"), "position", Vector2.Right * 300.0f, 1.0f).AsRelative().FromCurrent().SetTrans(Tween.TransitionType.Expo);
  584. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  585. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  586. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  587. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  588. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  589. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  590. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  591. .. |void| replace:: :abbr:`void (No return value.)`