class_animationplayer.rst 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the AnimationPlayer.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_AnimationPlayer:
  5. AnimationPlayer
  6. ===============
  7. **Inherits:** :ref:`Node<class_node>` **<** :ref:`Object<class_object>`
  8. **Category:** Core
  9. Brief Description
  10. -----------------
  11. Container and player of :ref:`Animation<class_animation>` resources.
  12. Member Functions
  13. ----------------
  14. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  15. | :ref:`int<class_int>` | :ref:`add_animation<class_AnimationPlayer_add_animation>` **(** :ref:`String<class_string>` name, :ref:`Animation<class_animation>` animation **)** |
  16. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  17. | void | :ref:`advance<class_AnimationPlayer_advance>` **(** :ref:`float<class_float>` delta **)** |
  18. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`String<class_string>` | :ref:`animation_get_next<class_AnimationPlayer_animation_get_next>` **(** :ref:`String<class_string>` anim_from **)** const |
  20. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | void | :ref:`animation_set_next<class_AnimationPlayer_animation_set_next>` **(** :ref:`String<class_string>` anim_from, :ref:`String<class_string>` anim_to **)** |
  22. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | void | :ref:`clear_caches<class_AnimationPlayer_clear_caches>` **(** **)** |
  24. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | void | :ref:`clear_queue<class_AnimationPlayer_clear_queue>` **(** **)** |
  26. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`String<class_string>` | :ref:`find_animation<class_AnimationPlayer_find_animation>` **(** :ref:`Animation<class_animation>` animation **)** const |
  28. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Animation<class_animation>` | :ref:`get_animation<class_AnimationPlayer_get_animation>` **(** :ref:`String<class_string>` name **)** const |
  30. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`PoolStringArray<class_poolstringarray>` | :ref:`get_animation_list<class_AnimationPlayer_get_animation_list>` **(** **)** const |
  32. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`String<class_string>` | :ref:`get_autoplay<class_AnimationPlayer_get_autoplay>` **(** **)** const |
  34. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`float<class_float>` | :ref:`get_blend_time<class_AnimationPlayer_get_blend_time>` **(** :ref:`String<class_string>` anim_from, :ref:`String<class_string>` anim_to **)** const |
  36. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`String<class_string>` | :ref:`get_current_animation<class_AnimationPlayer_get_current_animation>` **(** **)** const |
  38. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`float<class_float>` | :ref:`get_current_animation_length<class_AnimationPlayer_get_current_animation_length>` **(** **)** const |
  40. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`float<class_float>` | :ref:`get_current_animation_position<class_AnimationPlayer_get_current_animation_position>` **(** **)** const |
  42. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`float<class_float>` | :ref:`get_speed_scale<class_AnimationPlayer_get_speed_scale>` **(** **)** const |
  44. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`bool<class_bool>` | :ref:`has_animation<class_AnimationPlayer_has_animation>` **(** :ref:`String<class_string>` name **)** const |
  46. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`is_active<class_AnimationPlayer_is_active>` **(** **)** const |
  48. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`bool<class_bool>` | :ref:`is_playing<class_AnimationPlayer_is_playing>` **(** **)** const |
  50. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`play<class_AnimationPlayer_play>` **(** :ref:`String<class_string>` name="", :ref:`float<class_float>` custom_blend=-1, :ref:`float<class_float>` custom_speed=1.0, :ref:`bool<class_bool>` from_end=false **)** |
  52. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`play_backwards<class_AnimationPlayer_play_backwards>` **(** :ref:`String<class_string>` name="", :ref:`float<class_float>` custom_blend=-1 **)** |
  54. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`queue<class_AnimationPlayer_queue>` **(** :ref:`String<class_string>` name **)** |
  56. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`remove_animation<class_AnimationPlayer_remove_animation>` **(** :ref:`String<class_string>` name **)** |
  58. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`rename_animation<class_AnimationPlayer_rename_animation>` **(** :ref:`String<class_string>` name, :ref:`String<class_string>` newname **)** |
  60. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`seek<class_AnimationPlayer_seek>` **(** :ref:`float<class_float>` seconds, :ref:`bool<class_bool>` update=false **)** |
  62. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`set_active<class_AnimationPlayer_set_active>` **(** :ref:`bool<class_bool>` active **)** |
  64. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`set_autoplay<class_AnimationPlayer_set_autoplay>` **(** :ref:`String<class_string>` name **)** |
  66. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`set_blend_time<class_AnimationPlayer_set_blend_time>` **(** :ref:`String<class_string>` anim_from, :ref:`String<class_string>` anim_to, :ref:`float<class_float>` sec **)** |
  68. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`set_current_animation<class_AnimationPlayer_set_current_animation>` **(** :ref:`String<class_string>` anim **)** |
  70. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`set_speed_scale<class_AnimationPlayer_set_speed_scale>` **(** :ref:`float<class_float>` speed **)** |
  72. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`stop<class_AnimationPlayer_stop>` **(** :ref:`bool<class_bool>` reset=true **)** |
  74. +------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. Signals
  76. -------
  77. .. _class_AnimationPlayer_animation_changed:
  78. - **animation_changed** **(** :ref:`String<class_string>` old_name, :ref:`String<class_string>` new_name **)**
  79. If the currently being played animation changes, this signal will notify of such change.
  80. .. _class_AnimationPlayer_animation_finished:
  81. - **animation_finished** **(** :ref:`String<class_string>` name **)**
  82. Notifies when an animation finished playing.
  83. .. _class_AnimationPlayer_animation_started:
  84. - **animation_started** **(** :ref:`String<class_string>` name **)**
  85. Notifies when an animation starts playing.
  86. Member Variables
  87. ----------------
  88. .. _class_AnimationPlayer_playback_default_blend_time:
  89. - :ref:`float<class_float>` **playback_default_blend_time** - The default time in which to blend animations. Ranges from 0 to 4096 with 0.01 precision. Default value: ``0``.
  90. .. _class_AnimationPlayer_playback_process_mode:
  91. - :ref:`int<class_int>` **playback_process_mode** - The process notification in which to update animations. Default value: enum ANIMATION_PROCESS_IDLE.
  92. .. _class_AnimationPlayer_root_node:
  93. - :ref:`NodePath<class_nodepath>` **root_node** - The node from which node path references will travel. Default value: ``".."``.
  94. Numeric Constants
  95. -----------------
  96. - **ANIMATION_PROCESS_PHYSICS** = **0** --- Process animation during the physics process. This is especially useful when animating physics bodies.
  97. - **ANIMATION_PROCESS_IDLE** = **1** --- Process animation during the idle process.
  98. Description
  99. -----------
  100. An animation player is used for general purpose playback of :ref:`Animation<class_animation>` resources. It contains a dictionary of animations (referenced by name) and custom blend times between their transitions. Additionally, animations can be played and blended in different channels.
  101. Member Function Description
  102. ---------------------------
  103. .. _class_AnimationPlayer_add_animation:
  104. - :ref:`int<class_int>` **add_animation** **(** :ref:`String<class_string>` name, :ref:`Animation<class_animation>` animation **)**
  105. Adds ``animation`` to the player accessible with the key ``name``.
  106. .. _class_AnimationPlayer_advance:
  107. - void **advance** **(** :ref:`float<class_float>` delta **)**
  108. Shifts position in the animation timeline. Delta is the time in seconds to shift.
  109. .. _class_AnimationPlayer_animation_get_next:
  110. - :ref:`String<class_string>` **animation_get_next** **(** :ref:`String<class_string>` anim_from **)** const
  111. Returns the name of the next animation in the queue.
  112. .. _class_AnimationPlayer_animation_set_next:
  113. - void **animation_set_next** **(** :ref:`String<class_string>` anim_from, :ref:`String<class_string>` anim_to **)**
  114. Triggers the ``anim_to`` animation when the ``anim_from`` animation completes.
  115. .. _class_AnimationPlayer_clear_caches:
  116. - void **clear_caches** **(** **)**
  117. ``AnimationPlayer`` caches animated nodes. It may not notice if a node disappears, so clear_caches forces it to update the cache again.
  118. .. _class_AnimationPlayer_clear_queue:
  119. - void **clear_queue** **(** **)**
  120. Clears all queued, unplayed animations.
  121. .. _class_AnimationPlayer_find_animation:
  122. - :ref:`String<class_string>` **find_animation** **(** :ref:`Animation<class_animation>` animation **)** const
  123. Returns the name of ``animation`` or empty string if not found.
  124. .. _class_AnimationPlayer_get_animation:
  125. - :ref:`Animation<class_animation>` **get_animation** **(** :ref:`String<class_string>` name **)** const
  126. Returns the :ref:`Animation<class_animation>` with key ``name`` or ``null`` if not found.
  127. .. _class_AnimationPlayer_get_animation_list:
  128. - :ref:`PoolStringArray<class_poolstringarray>` **get_animation_list** **(** **)** const
  129. Returns the list of stored animation names.
  130. .. _class_AnimationPlayer_get_autoplay:
  131. - :ref:`String<class_string>` **get_autoplay** **(** **)** const
  132. Returns the name of the animation that will be automatically played when the scene is loaded.
  133. .. _class_AnimationPlayer_get_blend_time:
  134. - :ref:`float<class_float>` **get_blend_time** **(** :ref:`String<class_string>` anim_from, :ref:`String<class_string>` anim_to **)** const
  135. Get the blend time (in seconds) between two animations, referenced by their names.
  136. .. _class_AnimationPlayer_get_current_animation:
  137. - :ref:`String<class_string>` **get_current_animation** **(** **)** const
  138. Returns the name of the animation being played.
  139. .. _class_AnimationPlayer_get_current_animation_length:
  140. - :ref:`float<class_float>` **get_current_animation_length** **(** **)** const
  141. Get the length (in seconds) of the currently being played animation.
  142. .. _class_AnimationPlayer_get_current_animation_position:
  143. - :ref:`float<class_float>` **get_current_animation_position** **(** **)** const
  144. Get the position (in seconds) of the currently playing animation.
  145. .. _class_AnimationPlayer_get_speed_scale:
  146. - :ref:`float<class_float>` **get_speed_scale** **(** **)** const
  147. Returns the speed scaling ratio of the current animation channel. For instance, if this value is 1 then the animation plays at normal speed. If it's 0.5 then it plays at half speed. If it's 2 then it plays at double speed.
  148. .. _class_AnimationPlayer_has_animation:
  149. - :ref:`bool<class_bool>` **has_animation** **(** :ref:`String<class_string>` name **)** const
  150. Returns ``true`` if the ``AnimationPlayer`` stores an :ref:`Animation<class_animation>` with key ``name``.
  151. .. _class_AnimationPlayer_is_active:
  152. - :ref:`bool<class_bool>` **is_active** **(** **)** const
  153. Returns ``true`` if the player is active.
  154. .. _class_AnimationPlayer_is_playing:
  155. - :ref:`bool<class_bool>` **is_playing** **(** **)** const
  156. Returns ``true`` if playing an animation.
  157. .. _class_AnimationPlayer_play:
  158. - void **play** **(** :ref:`String<class_string>` name="", :ref:`float<class_float>` custom_blend=-1, :ref:`float<class_float>` custom_speed=1.0, :ref:`bool<class_bool>` from_end=false **)**
  159. Play the animation with key ``name``. Custom speed and blend times can be set. If custom speed is negative (-1), 'from_end' being true can play the
  160. animation backwards.
  161. .. _class_AnimationPlayer_play_backwards:
  162. - void **play_backwards** **(** :ref:`String<class_string>` name="", :ref:`float<class_float>` custom_blend=-1 **)**
  163. Play the animation with key ``name`` in reverse.
  164. .. _class_AnimationPlayer_queue:
  165. - void **queue** **(** :ref:`String<class_string>` name **)**
  166. Queue an animation for playback once the current one is done.
  167. .. _class_AnimationPlayer_remove_animation:
  168. - void **remove_animation** **(** :ref:`String<class_string>` name **)**
  169. Remove the animation with key ``name``.
  170. .. _class_AnimationPlayer_rename_animation:
  171. - void **rename_animation** **(** :ref:`String<class_string>` name, :ref:`String<class_string>` newname **)**
  172. Rename an existing animation with key ``name`` to ``newname``.
  173. .. _class_AnimationPlayer_seek:
  174. - void **seek** **(** :ref:`float<class_float>` seconds, :ref:`bool<class_bool>` update=false **)**
  175. Seek the animation to the ``seconds`` point in time (in seconds). If ``update`` is ``true``, the animation updates too, otherwise it updates at process time.
  176. .. _class_AnimationPlayer_set_active:
  177. - void **set_active** **(** :ref:`bool<class_bool>` active **)**
  178. Sets the player as active (playing). If ``true``, updates animations in response to process-related notifications. Default value: ``true``.
  179. .. _class_AnimationPlayer_set_autoplay:
  180. - void **set_autoplay** **(** :ref:`String<class_string>` name **)**
  181. Defines the name of the animation to play when the scene loads. Default value: ``""``.
  182. .. _class_AnimationPlayer_set_blend_time:
  183. - void **set_blend_time** **(** :ref:`String<class_string>` anim_from, :ref:`String<class_string>` anim_to, :ref:`float<class_float>` sec **)**
  184. Specify a blend time (in seconds) between two animations, referenced by their names.
  185. .. _class_AnimationPlayer_set_current_animation:
  186. - void **set_current_animation** **(** :ref:`String<class_string>` anim **)**
  187. Sets the name of the current animation. If already playing, restarts the animation. Ensure :ref:`active<class_AnimationPlayer_active>` is ``true`` to simulate :ref:`play<class_AnimationPlayer_play>`. Default value: ``""``.
  188. .. _class_AnimationPlayer_set_speed_scale:
  189. - void **set_speed_scale** **(** :ref:`float<class_float>` speed **)**
  190. Sets the speed scaling ratio in a given animation channel (or channel 0 if none is provided). Default value: ``1``.
  191. .. _class_AnimationPlayer_stop:
  192. - void **stop** **(** :ref:`bool<class_bool>` reset=true **)**
  193. Stop the currently playing animation. If ``reset`` is ``true``, the anim position is reset to ``0``.