class_tween.rst 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Tween.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Tween:
  6. Tween
  7. =====
  8. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  9. Lightweight object used for general-purpose animation via script, using :ref:`Tweener<class_Tweener>`\ s.
  10. Description
  11. -----------
  12. 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.
  13. \ ``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.
  14. A ``Tween`` can be created by using either :ref:`SceneTree.create_tween<class_SceneTree_method_create_tween>` or :ref:`Node.create_tween<class_Node_method_create_tween>`. ``Tween``\ s created manually (i.e. by using ``Tween.new()``) are invalid. They can't be used for tweening values, but you can do manual interpolation with :ref:`interpolate_value<class_Tween_method_interpolate_value>`.
  15. A ``Tween`` animation is composed of a sequence of :ref:`Tweener<class_Tweener>`\ s, which by default are executed one after another. You can create a sequence by appending :ref:`Tweener<class_Tweener>`\ s to the ``Tween``. Animating something with a :ref:`Tweener<class_Tweener>` is called tweening. Example tweening sequence looks like this:
  16. ::
  17. var tween = get_tree().create_tween()
  18. tween.tween_property($Sprite, "modulate", Color.red, 1)
  19. tween.tween_property($Sprite, "scale", Vector2(), 1)
  20. tween.tween_callback($Sprite.queue_free)
  21. This sequence will make the ``$Sprite`` node turn red, then shrink and finally the :ref:`Node.queue_free<class_Node_method_queue_free>` is called to remove the sprite. See methods :ref:`tween_property<class_Tween_method_tween_property>`, :ref:`tween_interval<class_Tween_method_tween_interval>`, :ref:`tween_callback<class_Tween_method_tween_callback>` and :ref:`tween_method<class_Tween_method_tween_method>` for more usage information.
  22. When a :ref:`Tweener<class_Tweener>` is created with one of the ``tween_*`` methods, a chained method call can be used to tweak the properties of this :ref:`Tweener<class_Tweener>`. For example, if you want to set different transition type in the above example, you can do:
  23. ::
  24. var tween = get_tree().create_tween()
  25. tween.tween_property($Sprite, "modulate", Color.red, 1).set_trans(Tween.TRANS_SINE)
  26. tween.tween_property($Sprite, "scale", Vector2(), 1).set_trans(Tween.TRANS_BOUNCE)
  27. tween.tween_callback($Sprite.queue_free)
  28. Most of the ``Tween`` methods can be chained this way too. In this example the ``Tween`` is bound and have set a default transition:
  29. ::
  30. var tween = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_ELASTIC)
  31. tween.tween_property($Sprite, "modulate", Color.red, 1)
  32. tween.tween_property($Sprite, "scale", Vector2(), 1)
  33. tween.tween_callback($Sprite.queue_free)
  34. Another interesting use for ``Tween``\ s is animating arbitrary set of objects:
  35. ::
  36. var tween = create_tween()
  37. for sprite in get_children():
  38. tween.tween_property(sprite, "position", Vector2(), 1)
  39. In the example above, all children of a node are moved one after another to position (0, 0).
  40. Some :ref:`Tweener<class_Tweener>`\ s use transitions and eases. The first accepts an :ref:`TransitionType<enum_Tween_TransitionType>` constant, and refers to the way the timing of the animation is handled (see `easings.net <https://easings.net/>`__ for some examples). The second accepts an :ref:`EaseType<enum_Tween_EaseType>` constant, and controls where the ``trans_type`` is applied to the interpolation (in the beginning, the end, or both). If you don't know which transition and easing to pick, you can try different :ref:`TransitionType<enum_Tween_TransitionType>` constants with :ref:`EASE_IN_OUT<class_Tween_constant_EASE_IN_OUT>`, and use the one that looks best.
  41. \ `Tween easing and transition types cheatsheet <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/tween_cheatsheet.png>`__\
  42. \ **Note:** All ``Tween``\ s will automatically start by default. To prevent a ``Tween`` from autostarting, you can call :ref:`stop<class_Tween_method_stop>` immediately after it was created.
  43. Methods
  44. -------
  45. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Tween<class_Tween>` | :ref:`bind_node<class_Tween_method_bind_node>` **(** :ref:`Node<class_Node>` node **)** |
  47. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`Tween<class_Tween>` | :ref:`chain<class_Tween_method_chain>` **(** **)** |
  49. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`bool<class_bool>` | :ref:`custom_step<class_Tween_method_custom_step>` **(** :ref:`float<class_float>` delta **)** |
  51. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Variant<class_Variant>` | :ref:`interpolate_value<class_Tween_method_interpolate_value>` **(** :ref:`Variant<class_Variant>` initial_value, :ref:`Variant<class_Variant>` delta_value, :ref:`float<class_float>` elapsed_time, :ref:`float<class_float>` duration, :ref:`TransitionType<enum_Tween_TransitionType>` trans_type, :ref:`EaseType<enum_Tween_EaseType>` ease_type **)** |
  53. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`bool<class_bool>` | :ref:`is_running<class_Tween_method_is_running>` **(** **)** |
  55. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`bool<class_bool>` | :ref:`is_valid<class_Tween_method_is_valid>` **(** **)** |
  57. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`kill<class_Tween_method_kill>` **(** **)** |
  59. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Tween<class_Tween>` | :ref:`parallel<class_Tween_method_parallel>` **(** **)** |
  61. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`pause<class_Tween_method_pause>` **(** **)** |
  63. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`play<class_Tween_method_play>` **(** **)** |
  65. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`Tween<class_Tween>` | :ref:`set_ease<class_Tween_method_set_ease>` **(** :ref:`EaseType<enum_Tween_EaseType>` ease **)** |
  67. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`Tween<class_Tween>` | :ref:`set_loops<class_Tween_method_set_loops>` **(** :ref:`int<class_int>` loops=0 **)** |
  69. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Tween<class_Tween>` | :ref:`set_parallel<class_Tween_method_set_parallel>` **(** :ref:`bool<class_bool>` parallel=true **)** |
  71. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`Tween<class_Tween>` | :ref:`set_pause_mode<class_Tween_method_set_pause_mode>` **(** :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>` mode **)** |
  73. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`Tween<class_Tween>` | :ref:`set_process_mode<class_Tween_method_set_process_mode>` **(** :ref:`TweenProcessMode<enum_Tween_TweenProcessMode>` mode **)** |
  75. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`Tween<class_Tween>` | :ref:`set_speed_scale<class_Tween_method_set_speed_scale>` **(** :ref:`float<class_float>` speed **)** |
  77. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`Tween<class_Tween>` | :ref:`set_trans<class_Tween_method_set_trans>` **(** :ref:`TransitionType<enum_Tween_TransitionType>` trans **)** |
  79. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`stop<class_Tween_method_stop>` **(** **)** |
  81. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`CallbackTweener<class_CallbackTweener>` | :ref:`tween_callback<class_Tween_method_tween_callback>` **(** :ref:`Callable<class_Callable>` callback **)** |
  83. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`IntervalTweener<class_IntervalTweener>` | :ref:`tween_interval<class_Tween_method_tween_interval>` **(** :ref:`float<class_float>` time **)** |
  85. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`MethodTweener<class_MethodTweener>` | :ref:`tween_method<class_Tween_method_tween_method>` **(** :ref:`Callable<class_Callable>` method, :ref:`Variant<class_Variant>` from, :ref:`Variant<class_Variant>` to, :ref:`float<class_float>` duration **)** |
  87. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`PropertyTweener<class_PropertyTweener>` | :ref:`tween_property<class_Tween_method_tween_property>` **(** :ref:`Object<class_Object>` object, :ref:`NodePath<class_NodePath>` property, :ref:`Variant<class_Variant>` final_val, :ref:`float<class_float>` duration **)** |
  89. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. Signals
  91. -------
  92. .. _class_Tween_signal_finished:
  93. - **finished** **(** **)**
  94. 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>`).
  95. \ **Note:** The ``Tween`` is removed (invalidated) after this signal is emitted, but it doesn't happen immediately, but on the next processing frame. Calling :ref:`stop<class_Tween_method_stop>` inside the signal callback will preserve the ``Tween``.
  96. ----
  97. .. _class_Tween_signal_loop_finished:
  98. - **loop_finished** **(** :ref:`int<class_int>` loop_count **)**
  99. Emitted when a full loop is complete (see :ref:`set_loops<class_Tween_method_set_loops>`), providing the loop index. This signal is not emitted after final loop, use :ref:`finished<class_Tween_signal_finished>` instead for this case.
  100. ----
  101. .. _class_Tween_signal_step_finished:
  102. - **step_finished** **(** :ref:`int<class_int>` idx **)**
  103. Emitted when one step of the ``Tween`` is complete, providing the step index. One step is either a single :ref:`Tweener<class_Tweener>` or a group of :ref:`Tweener<class_Tweener>`\ s running parallelly.
  104. Enumerations
  105. ------------
  106. .. _enum_Tween_TweenProcessMode:
  107. .. _class_Tween_constant_TWEEN_PROCESS_PHYSICS:
  108. .. _class_Tween_constant_TWEEN_PROCESS_IDLE:
  109. enum **TweenProcessMode**:
  110. - **TWEEN_PROCESS_PHYSICS** = **0** --- The ``Tween`` updates during the physics frame.
  111. - **TWEEN_PROCESS_IDLE** = **1** --- The ``Tween`` updates during the idle frame.
  112. ----
  113. .. _enum_Tween_TweenPauseMode:
  114. .. _class_Tween_constant_TWEEN_PAUSE_BOUND:
  115. .. _class_Tween_constant_TWEEN_PAUSE_STOP:
  116. .. _class_Tween_constant_TWEEN_PAUSE_PROCESS:
  117. enum **TweenPauseMode**:
  118. - **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>`.
  119. - **TWEEN_PAUSE_STOP** = **1** --- If :ref:`SceneTree<class_SceneTree>` is paused, the ``Tween`` will also pause.
  120. - **TWEEN_PAUSE_PROCESS** = **2** --- The ``Tween`` will process regardless of whether :ref:`SceneTree<class_SceneTree>` is paused.
  121. ----
  122. .. _enum_Tween_TransitionType:
  123. .. _class_Tween_constant_TRANS_LINEAR:
  124. .. _class_Tween_constant_TRANS_SINE:
  125. .. _class_Tween_constant_TRANS_QUINT:
  126. .. _class_Tween_constant_TRANS_QUART:
  127. .. _class_Tween_constant_TRANS_QUAD:
  128. .. _class_Tween_constant_TRANS_EXPO:
  129. .. _class_Tween_constant_TRANS_ELASTIC:
  130. .. _class_Tween_constant_TRANS_CUBIC:
  131. .. _class_Tween_constant_TRANS_CIRC:
  132. .. _class_Tween_constant_TRANS_BOUNCE:
  133. .. _class_Tween_constant_TRANS_BACK:
  134. enum **TransitionType**:
  135. - **TRANS_LINEAR** = **0** --- The animation is interpolated linearly.
  136. - **TRANS_SINE** = **1** --- The animation is interpolated using a sine function.
  137. - **TRANS_QUINT** = **2** --- The animation is interpolated with a quintic (to the power of 5) function.
  138. - **TRANS_QUART** = **3** --- The animation is interpolated with a quartic (to the power of 4) function.
  139. - **TRANS_QUAD** = **4** --- The animation is interpolated with a quadratic (to the power of 2) function.
  140. - **TRANS_EXPO** = **5** --- The animation is interpolated with an exponential (to the power of x) function.
  141. - **TRANS_ELASTIC** = **6** --- The animation is interpolated with elasticity, wiggling around the edges.
  142. - **TRANS_CUBIC** = **7** --- The animation is interpolated with a cubic (to the power of 3) function.
  143. - **TRANS_CIRC** = **8** --- The animation is interpolated with a function using square roots.
  144. - **TRANS_BOUNCE** = **9** --- The animation is interpolated by bouncing at the end.
  145. - **TRANS_BACK** = **10** --- The animation is interpolated backing out at ends.
  146. ----
  147. .. _enum_Tween_EaseType:
  148. .. _class_Tween_constant_EASE_IN:
  149. .. _class_Tween_constant_EASE_OUT:
  150. .. _class_Tween_constant_EASE_IN_OUT:
  151. .. _class_Tween_constant_EASE_OUT_IN:
  152. enum **EaseType**:
  153. - **EASE_IN** = **0** --- The interpolation starts slowly and speeds up towards the end.
  154. - **EASE_OUT** = **1** --- The interpolation starts quickly and slows down towards the end.
  155. - **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.
  156. - **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.
  157. Method Descriptions
  158. -------------------
  159. .. _class_Tween_method_bind_node:
  160. - :ref:`Tween<class_Tween>` **bind_node** **(** :ref:`Node<class_Node>` node **)**
  161. 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.
  162. For a shorter way to create and bind a ``Tween``, you can use :ref:`Node.create_tween<class_Node_method_create_tween>`.
  163. ----
  164. .. _class_Tween_method_chain:
  165. - :ref:`Tween<class_Tween>` **chain** **(** **)**
  166. Used to chain two :ref:`Tweener<class_Tweener>`\ s after :ref:`set_parallel<class_Tween_method_set_parallel>` is called with ``true``.
  167. ::
  168. var tween = create_tween().set_parallel(true)
  169. tween.tween_property(...)
  170. tween.tween_property(...) # Will run parallelly with above.
  171. tween.chain().tween_property(...) # Will run after two above are finished.
  172. ----
  173. .. _class_Tween_method_custom_step:
  174. - :ref:`bool<class_bool>` **custom_step** **(** :ref:`float<class_float>` delta **)**
  175. Processes the ``Tween`` by given ``delta`` value, in seconds. Mostly useful when the ``Tween`` is paused, for controlling it manually. Can also be used to end the ``Tween`` animation immediately, by using ``delta`` longer than the whole duration.
  176. Returns ``true`` if the ``Tween`` still has :ref:`Tweener<class_Tweener>`\ s that haven't finished.
  177. \ **Note:** The ``Tween`` will become invalid after finished, but you can call :ref:`stop<class_Tween_method_stop>` after the step, to keep it and reset.
  178. ----
  179. .. _class_Tween_method_interpolate_value:
  180. - :ref:`Variant<class_Variant>` **interpolate_value** **(** :ref:`Variant<class_Variant>` initial_value, :ref:`Variant<class_Variant>` delta_value, :ref:`float<class_float>` elapsed_time, :ref:`float<class_float>` duration, :ref:`TransitionType<enum_Tween_TransitionType>` trans_type, :ref:`EaseType<enum_Tween_EaseType>` ease_type **)**
  181. 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.
  182. \ ``initial_value`` is the starting value of the interpolation.
  183. \ ``delta_value`` is the change of the value in the interpolation, i.e. it's equal to ``final_value - initial_value``.
  184. \ ``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.
  185. \ ``duration`` is the total time of the interpolation.
  186. \ **Note:** If ``duration`` is equal to ``0``, the method will always return the final value, regardless of ``elapsed_time`` provided.
  187. ----
  188. .. _class_Tween_method_is_running:
  189. - :ref:`bool<class_bool>` **is_running** **(** **)**
  190. Returns whether the ``Tween`` is currently running, i.e. it wasn't paused and it's not finished.
  191. ----
  192. .. _class_Tween_method_is_valid:
  193. - :ref:`bool<class_bool>` **is_valid** **(** **)**
  194. Returns whether the ``Tween`` is valid. A valid ``Tween`` is a ``Tween`` contained by the scene tree (i.e. the array from :ref:`SceneTree.get_processed_tweens<class_SceneTree_method_get_processed_tweens>` will contain this ``Tween``). ``Tween`` might become invalid when it has finished tweening or was killed, also when created with ``Tween.new()``. Invalid ``Tween`` can't have :ref:`Tweener<class_Tweener>`\ s appended, because it can't animate them. You can however still use :ref:`interpolate_value<class_Tween_method_interpolate_value>`.
  195. ----
  196. .. _class_Tween_method_kill:
  197. - void **kill** **(** **)**
  198. Aborts all tweening operations and invalidates the ``Tween``.
  199. ----
  200. .. _class_Tween_method_parallel:
  201. - :ref:`Tween<class_Tween>` **parallel** **(** **)**
  202. Makes the next :ref:`Tweener<class_Tweener>` run parallelly to the previous one. Example:
  203. ::
  204. var tween = create_tween()
  205. tween.tween_property(...)
  206. tween.parallel().tween_property(...)
  207. tween.parallel().tween_property(...)
  208. All :ref:`Tweener<class_Tweener>`\ s in the example will run at the same time.
  209. You can make the ``Tween`` parallel by default by using :ref:`set_parallel<class_Tween_method_set_parallel>`.
  210. ----
  211. .. _class_Tween_method_pause:
  212. - void **pause** **(** **)**
  213. Pauses the tweening. The animation can be resumed by using :ref:`play<class_Tween_method_play>`.
  214. ----
  215. .. _class_Tween_method_play:
  216. - void **play** **(** **)**
  217. Resumes a paused or stopped ``Tween``.
  218. ----
  219. .. _class_Tween_method_set_ease:
  220. - :ref:`Tween<class_Tween>` **set_ease** **(** :ref:`EaseType<enum_Tween_EaseType>` ease **)**
  221. Sets the default ease type for :ref:`PropertyTweener<class_PropertyTweener>`\ s and :ref:`MethodTweener<class_MethodTweener>`\ s animated by this ``Tween``.
  222. ----
  223. .. _class_Tween_method_set_loops:
  224. - :ref:`Tween<class_Tween>` **set_loops** **(** :ref:`int<class_int>` loops=0 **)**
  225. Sets the number of times the tweening sequence will be repeated, i.e. ``set_loops(2)`` will run the animation twice.
  226. Calling this method without arguments will make the ``Tween`` run infinitely, until it is either killed by :ref:`kill<class_Tween_method_kill>` or by freeing bound node, or all the animated objects have been freed (which makes further animation impossible).
  227. \ **Warning:** Make sure to always add some duration/delay when using infinite loops. 0-duration looped animations (e.g. single :ref:`CallbackTweener<class_CallbackTweener>` with no delay or :ref:`PropertyTweener<class_PropertyTweener>` with invalid node) are equivalent to infinite ``while`` loops and will freeze your game. If a ``Tween``'s lifetime depends on some node, always use :ref:`bind_node<class_Tween_method_bind_node>`.
  228. ----
  229. .. _class_Tween_method_set_parallel:
  230. - :ref:`Tween<class_Tween>` **set_parallel** **(** :ref:`bool<class_bool>` parallel=true **)**
  231. If ``parallel`` is ``true``, the :ref:`Tweener<class_Tweener>`\ s appended after this method will by default run simultaneously, as opposed to sequentially.
  232. ----
  233. .. _class_Tween_method_set_pause_mode:
  234. - :ref:`Tween<class_Tween>` **set_pause_mode** **(** :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>` mode **)**
  235. Determines the behavior of the ``Tween`` when the :ref:`SceneTree<class_SceneTree>` is paused. Check :ref:`TweenPauseMode<enum_Tween_TweenPauseMode>` for options.
  236. Default value is :ref:`TWEEN_PAUSE_BOUND<class_Tween_constant_TWEEN_PAUSE_BOUND>`.
  237. ----
  238. .. _class_Tween_method_set_process_mode:
  239. - :ref:`Tween<class_Tween>` **set_process_mode** **(** :ref:`TweenProcessMode<enum_Tween_TweenProcessMode>` mode **)**
  240. Determines whether the ``Tween`` should run during idle frame (see :ref:`Node._process<class_Node_method__process>`) or physics frame (see :ref:`Node._physics_process<class_Node_method__physics_process>`.
  241. Default value is :ref:`TWEEN_PROCESS_IDLE<class_Tween_constant_TWEEN_PROCESS_IDLE>`.
  242. ----
  243. .. _class_Tween_method_set_speed_scale:
  244. - :ref:`Tween<class_Tween>` **set_speed_scale** **(** :ref:`float<class_float>` speed **)**
  245. Scales the speed of tweening. This affects all :ref:`Tweener<class_Tweener>`\ s and their delays.
  246. ----
  247. .. _class_Tween_method_set_trans:
  248. - :ref:`Tween<class_Tween>` **set_trans** **(** :ref:`TransitionType<enum_Tween_TransitionType>` trans **)**
  249. Sets the default transition type for :ref:`PropertyTweener<class_PropertyTweener>`\ s and :ref:`MethodTweener<class_MethodTweener>`\ s animated by this ``Tween``.
  250. ----
  251. .. _class_Tween_method_stop:
  252. - void **stop** **(** **)**
  253. Stops the tweening and resets the ``Tween`` to its initial state. This will not remove any appended :ref:`Tweener<class_Tweener>`\ s.
  254. ----
  255. .. _class_Tween_method_tween_callback:
  256. - :ref:`CallbackTweener<class_CallbackTweener>` **tween_callback** **(** :ref:`Callable<class_Callable>` callback **)**
  257. 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.
  258. Example: object that keeps shooting every 1 second.
  259. ::
  260. var tween = get_tree().create_tween().set_loops()
  261. tween.tween_callback(shoot).set_delay(1)
  262. Example: turning a sprite red and then blue, with 2 second delay.
  263. ::
  264. var tween = get_tree().create_tween()
  265. tween.tween_callback($Sprite.set_modulate.bind(Color.red)).set_delay(2)
  266. tween.tween_callback($Sprite.set_modulate.bind(Color.blue)).set_delay(2)
  267. ----
  268. .. _class_Tween_method_tween_interval:
  269. - :ref:`IntervalTweener<class_IntervalTweener>` **tween_interval** **(** :ref:`float<class_float>` time **)**
  270. Creates and appends an :ref:`IntervalTweener<class_IntervalTweener>`. This method can be used to create delays in the tween animation, as an alternative for using the delay in other :ref:`Tweener<class_Tweener>`\ s or when there's no animation (in which case the ``Tween`` acts as a timer). ``time`` is the length of the interval, in seconds.
  271. Example: creating an interval in code execution.
  272. ::
  273. # ... some code
  274. await create_tween().tween_interval(2).finished
  275. # ... more code
  276. Example: creating an object that moves back and forth and jumps every few seconds.
  277. ::
  278. var tween = create_tween().set_loops()
  279. tween.tween_property("position:x", 200, 1).as_relative()
  280. tween.tween_callback(jump)
  281. tween.tween_interval(2)
  282. tween.tween_property("position:x", -200, 1).as_relative()
  283. tween.tween_callback(jump)
  284. tween.tween_interval(2)
  285. ----
  286. .. _class_Tween_method_tween_method:
  287. - :ref:`MethodTweener<class_MethodTweener>` **tween_method** **(** :ref:`Callable<class_Callable>` method, :ref:`Variant<class_Variant>` from, :ref:`Variant<class_Variant>` to, :ref:`float<class_float>` duration **)**
  288. 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.
  289. Example: making a 3D object look from one point to another point.
  290. ::
  291. var tween = create_tween()
  292. 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.
  293. Example: setting a text of a :ref:`Label<class_Label>`, using an intermediate method and after a delay.
  294. ::
  295. func _ready():
  296. var tween = create_tween()
  297. tween.tween_method(set_label_text, 0, 10, 1).set_delay(1)
  298. func set_label_text(value: int):
  299. $Label.text = "Counting " + str(value)
  300. ----
  301. .. _class_Tween_method_tween_property:
  302. - :ref:`PropertyTweener<class_PropertyTweener>` **tween_property** **(** :ref:`Object<class_Object>` object, :ref:`NodePath<class_NodePath>` property, :ref:`Variant<class_Variant>` final_val, :ref:`float<class_float>` duration **)**
  303. Creates and appends a :ref:`PropertyTweener<class_PropertyTweener>`. This method tweens a ``property`` of an ``object`` between an initial value and ``final_val`` in a span of time equal to ``duration``, in seconds. The initial value by default is a value at the time the tweening of the :ref:`PropertyTweener<class_PropertyTweener>` start. For example:
  304. ::
  305. var tween = create_tween()
  306. tween.tween_property($Sprite, "position", Vector2(100, 200)
  307. tween.tween_property($Sprite, "position", Vector2(200, 300)
  308. 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.
  309. \ **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.
  310. Example: moving object twice from the same position, with different transition types.
  311. ::
  312. var tween = create_tween()
  313. tween.tween_property($Sprite, "position", Vector2.RIGHT * 300).as_relative().set_trans(Tween.TRANS_SINE)
  314. tween.tween_property($Sprite, "position", Vector2.RIGHT * 300).as_relative().from_current().set_trans(Tween.TRANS_EXPO)
  315. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  316. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  317. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  318. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  319. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  320. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`