class_animation.rst 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_Animation:
  4. Animation
  5. =========
  6. **Inherits:** :ref:`Resource<class_resource>` **<** :ref:`Reference<class_reference>` **<** :ref:`Object<class_object>`
  7. **Category:** Core
  8. Brief Description
  9. -----------------
  10. Contains data used to animate everything in the engine.
  11. Member Functions
  12. ----------------
  13. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | :ref:`int<class_int>` | :ref:`add_track<class_Animation_add_track>` **(** :ref:`int<class_int>` type, :ref:`int<class_int>` at_pos=-1 **)** |
  15. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | void | :ref:`remove_track<class_Animation_remove_track>` **(** :ref:`int<class_int>` idx **)** |
  17. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`int<class_int>` | :ref:`get_track_count<class_Animation_get_track_count>` **(** **)** const |
  19. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`int<class_int>` | :ref:`track_get_type<class_Animation_track_get_type>` **(** :ref:`int<class_int>` idx **)** const |
  21. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`NodePath<class_nodepath>` | :ref:`track_get_path<class_Animation_track_get_path>` **(** :ref:`int<class_int>` idx **)** const |
  23. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | void | :ref:`track_set_path<class_Animation_track_set_path>` **(** :ref:`int<class_int>` idx, :ref:`NodePath<class_nodepath>` path **)** |
  25. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`int<class_int>` | :ref:`find_track<class_Animation_find_track>` **(** :ref:`NodePath<class_nodepath>` path **)** const |
  27. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | void | :ref:`track_move_up<class_Animation_track_move_up>` **(** :ref:`int<class_int>` idx **)** |
  29. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | void | :ref:`track_move_down<class_Animation_track_move_down>` **(** :ref:`int<class_int>` idx **)** |
  31. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`int<class_int>` | :ref:`transform_track_insert_key<class_Animation_transform_track_insert_key>` **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` time, :ref:`Vector3<class_vector3>` loc, :ref:`Quat<class_quat>` rot, :ref:`Vector3<class_vector3>` scale **)** |
  33. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`track_insert_key<class_Animation_track_insert_key>` **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` time, var key, :ref:`float<class_float>` transition=1 **)** |
  35. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | void | :ref:`track_remove_key<class_Animation_track_remove_key>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx **)** |
  37. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | void | :ref:`track_remove_key_at_pos<class_Animation_track_remove_key_at_pos>` **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` pos **)** |
  39. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | void | :ref:`track_set_key_value<class_Animation_track_set_key_value>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key, var value **)** |
  41. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`track_set_key_transition<class_Animation_track_set_key_transition>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx, :ref:`float<class_float>` transition **)** |
  43. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`float<class_float>` | :ref:`track_get_key_transition<class_Animation_track_get_key_transition>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx **)** const |
  45. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`int<class_int>` | :ref:`track_get_key_count<class_Animation_track_get_key_count>` **(** :ref:`int<class_int>` idx **)** const |
  47. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`track_get_key_value<class_Animation_track_get_key_value>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx **)** const |
  49. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`float<class_float>` | :ref:`track_get_key_time<class_Animation_track_get_key_time>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx **)** const |
  51. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`int<class_int>` | :ref:`track_find_key<class_Animation_track_find_key>` **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` time, :ref:`bool<class_bool>` exact=false **)** const |
  53. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | void | :ref:`track_set_interpolation_type<class_Animation_track_set_interpolation_type>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` interpolation **)** |
  55. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`int<class_int>` | :ref:`track_get_interpolation_type<class_Animation_track_get_interpolation_type>` **(** :ref:`int<class_int>` idx **)** const |
  57. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`Array<class_array>` | :ref:`transform_track_interpolate<class_Animation_transform_track_interpolate>` **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` time_sec **)** const |
  59. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`value_track_set_continuous<class_Animation_value_track_set_continuous>` **(** :ref:`int<class_int>` idx, :ref:`bool<class_bool>` continuous **)** |
  61. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`bool<class_bool>` | :ref:`value_track_is_continuous<class_Animation_value_track_is_continuous>` **(** :ref:`int<class_int>` idx **)** const |
  63. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`IntArray<class_intarray>` | :ref:`value_track_get_key_indices<class_Animation_value_track_get_key_indices>` **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` time_sec, :ref:`float<class_float>` delta **)** const |
  65. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`IntArray<class_intarray>` | :ref:`method_track_get_key_indices<class_Animation_method_track_get_key_indices>` **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` time_sec, :ref:`float<class_float>` delta **)** const |
  67. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`String<class_string>` | :ref:`method_track_get_name<class_Animation_method_track_get_name>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx **)** const |
  69. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Array<class_array>` | :ref:`method_track_get_params<class_Animation_method_track_get_params>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx **)** const |
  71. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | void | :ref:`set_length<class_Animation_set_length>` **(** :ref:`float<class_float>` time_sec **)** |
  73. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`float<class_float>` | :ref:`get_length<class_Animation_get_length>` **(** **)** const |
  75. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | void | :ref:`set_loop<class_Animation_set_loop>` **(** :ref:`bool<class_bool>` enabled **)** |
  77. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`bool<class_bool>` | :ref:`has_loop<class_Animation_has_loop>` **(** **)** const |
  79. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`set_step<class_Animation_set_step>` **(** :ref:`float<class_float>` size_sec **)** |
  81. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`float<class_float>` | :ref:`get_step<class_Animation_get_step>` **(** **)** const |
  83. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | void | :ref:`clear<class_Animation_clear>` **(** **)** |
  85. +----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. Numeric Constants
  87. -----------------
  88. - **TYPE_VALUE** = **0** --- Value tracks set values in node properties, but only those which can be Interpolated.
  89. - **TYPE_TRANSFORM** = **1** --- Transform tracks are used to change node local transforms or skeleton pose bones. Transitions are Interpolated.
  90. - **TYPE_METHOD** = **2** --- Method tracks call functions with given arguments per key.
  91. - **INTERPOLATION_NEAREST** = **0** --- No interpolation (nearest value).
  92. - **INTERPOLATION_LINEAR** = **1** --- Linear interpolation.
  93. - **INTERPOLATION_CUBIC** = **2** --- Cubic interpolation.
  94. Description
  95. -----------
  96. An Animation resource contains data used to animate everything in the engine. Animations are divided into tracks, and each track must be linked to a node. The state of that node can be changed through time, by adding timed keys (events) to the track.
  97. Animations are just data containers, and must be added to odes such as an :ref:`AnimationPlayer<class_animationplayer>` or :ref:`AnimationTreePlayer<class_animationtreeplayer>` to be played back.
  98. Member Function Description
  99. ---------------------------
  100. .. _class_Animation_add_track:
  101. - :ref:`int<class_int>` **add_track** **(** :ref:`int<class_int>` type, :ref:`int<class_int>` at_pos=-1 **)**
  102. Add a track to the Animation. The track type must be specified as any of the values in the TYPE\_\* enumeration.
  103. .. _class_Animation_remove_track:
  104. - void **remove_track** **(** :ref:`int<class_int>` idx **)**
  105. Remove a track by specifying the track index.
  106. .. _class_Animation_get_track_count:
  107. - :ref:`int<class_int>` **get_track_count** **(** **)** const
  108. Return the amount of tracks in the animation.
  109. .. _class_Animation_track_get_type:
  110. - :ref:`int<class_int>` **track_get_type** **(** :ref:`int<class_int>` idx **)** const
  111. Get the type of a track.
  112. .. _class_Animation_track_get_path:
  113. - :ref:`NodePath<class_nodepath>` **track_get_path** **(** :ref:`int<class_int>` idx **)** const
  114. Get the path of a track. for more information on the path format, see :ref:`track_set_path<class_Animation_track_set_path>`
  115. .. _class_Animation_track_set_path:
  116. - void **track_set_path** **(** :ref:`int<class_int>` idx, :ref:`NodePath<class_nodepath>` path **)**
  117. Set the path of a track. Paths must be valid scene-tree paths to a node, and must be specified starting from the parent node of the node that will reproduce the animation. Tracks that control properties or bones must append their name after the path, separated by ":". Example: "character/skeleton:ankle" or "character/mesh:transform/local"
  118. .. _class_Animation_find_track:
  119. - :ref:`int<class_int>` **find_track** **(** :ref:`NodePath<class_nodepath>` path **)** const
  120. .. _class_Animation_track_move_up:
  121. - void **track_move_up** **(** :ref:`int<class_int>` idx **)**
  122. Move a track up.
  123. .. _class_Animation_track_move_down:
  124. - void **track_move_down** **(** :ref:`int<class_int>` idx **)**
  125. Move a track down.
  126. .. _class_Animation_transform_track_insert_key:
  127. - :ref:`int<class_int>` **transform_track_insert_key** **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` time, :ref:`Vector3<class_vector3>` loc, :ref:`Quat<class_quat>` rot, :ref:`Vector3<class_vector3>` scale **)**
  128. Insert a transform key for a transform track.
  129. .. _class_Animation_track_insert_key:
  130. - void **track_insert_key** **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` time, var key, :ref:`float<class_float>` transition=1 **)**
  131. Insert a generic key in a given track.
  132. .. _class_Animation_track_remove_key:
  133. - void **track_remove_key** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx **)**
  134. Remove a key by index in a given track.
  135. .. _class_Animation_track_remove_key_at_pos:
  136. - void **track_remove_key_at_pos** **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` pos **)**
  137. Remove a key by position (seconds) in a given track.
  138. .. _class_Animation_track_set_key_value:
  139. - void **track_set_key_value** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key, var value **)**
  140. Set the value of an existing key.
  141. .. _class_Animation_track_set_key_transition:
  142. - void **track_set_key_transition** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx, :ref:`float<class_float>` transition **)**
  143. Set the transition curve (easing) for a specific key (see built-in math function "ease").
  144. .. _class_Animation_track_get_key_transition:
  145. - :ref:`float<class_float>` **track_get_key_transition** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx **)** const
  146. Return the transition curve (easing) for a specific key (see built-in math function "ease").
  147. .. _class_Animation_track_get_key_count:
  148. - :ref:`int<class_int>` **track_get_key_count** **(** :ref:`int<class_int>` idx **)** const
  149. Return the amount of keys in a given track.
  150. .. _class_Animation_track_get_key_value:
  151. - void **track_get_key_value** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx **)** const
  152. Return the value of a given key in a given track.
  153. .. _class_Animation_track_get_key_time:
  154. - :ref:`float<class_float>` **track_get_key_time** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx **)** const
  155. Return the time at which the key is located.
  156. .. _class_Animation_track_find_key:
  157. - :ref:`int<class_int>` **track_find_key** **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` time, :ref:`bool<class_bool>` exact=false **)** const
  158. Find the key index by time in a given track. Optionally, only find it if the exact time is given.
  159. .. _class_Animation_track_set_interpolation_type:
  160. - void **track_set_interpolation_type** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` interpolation **)**
  161. Set the interpolation type of a given track, from the INTERPOLATION\_\* enum.
  162. .. _class_Animation_track_get_interpolation_type:
  163. - :ref:`int<class_int>` **track_get_interpolation_type** **(** :ref:`int<class_int>` idx **)** const
  164. Return the interpolation type of a given track, from the INTERPOLATION\_\* enum.
  165. .. _class_Animation_transform_track_interpolate:
  166. - :ref:`Array<class_array>` **transform_track_interpolate** **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` time_sec **)** const
  167. Return the interpolated value of a transform track at a given time (in seconds). An array consisting of 3 elements: position (:ref:`Vector3<class_vector3>`), rotation (:ref:`Quat<class_quat>`) and scale (:ref:`Vector3<class_vector3>`).
  168. .. _class_Animation_value_track_set_continuous:
  169. - void **value_track_set_continuous** **(** :ref:`int<class_int>` idx, :ref:`bool<class_bool>` continuous **)**
  170. Enable or disable interpolation for a whole track. By default tracks are interpolated.
  171. .. _class_Animation_value_track_is_continuous:
  172. - :ref:`bool<class_bool>` **value_track_is_continuous** **(** :ref:`int<class_int>` idx **)** const
  173. Return whether interpolation is enabled or disabled for a whole track. By default tracks are interpolated.
  174. .. _class_Animation_value_track_get_key_indices:
  175. - :ref:`IntArray<class_intarray>` **value_track_get_key_indices** **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` time_sec, :ref:`float<class_float>` delta **)** const
  176. Return all the key indices of a value track, given a position and delta time.
  177. .. _class_Animation_method_track_get_key_indices:
  178. - :ref:`IntArray<class_intarray>` **method_track_get_key_indices** **(** :ref:`int<class_int>` idx, :ref:`float<class_float>` time_sec, :ref:`float<class_float>` delta **)** const
  179. Return all the key indices of a method track, given a position and delta time.
  180. .. _class_Animation_method_track_get_name:
  181. - :ref:`String<class_string>` **method_track_get_name** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx **)** const
  182. Return the method name of a method track.
  183. .. _class_Animation_method_track_get_params:
  184. - :ref:`Array<class_array>` **method_track_get_params** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` key_idx **)** const
  185. Return the arguments values to be called on a method track for a given key in a given track.
  186. .. _class_Animation_set_length:
  187. - void **set_length** **(** :ref:`float<class_float>` time_sec **)**
  188. Set the total length of the animation (in seconds). Note that length is not delimited by the last key, as this one may be before or after the end to ensure correct interpolation and looping.
  189. .. _class_Animation_get_length:
  190. - :ref:`float<class_float>` **get_length** **(** **)** const
  191. Return the total length of the animation (in seconds).
  192. .. _class_Animation_set_loop:
  193. - void **set_loop** **(** :ref:`bool<class_bool>` enabled **)**
  194. Set a flag indicating that the animation must loop. This is uses for correct interpolation of animation cycles, and for hinting the player that it must restart the animation.
  195. .. _class_Animation_has_loop:
  196. - :ref:`bool<class_bool>` **has_loop** **(** **)** const
  197. Return whether the animation has the loop flag set.
  198. .. _class_Animation_set_step:
  199. - void **set_step** **(** :ref:`float<class_float>` size_sec **)**
  200. .. _class_Animation_get_step:
  201. - :ref:`float<class_float>` **get_step** **(** **)** const
  202. .. _class_Animation_clear:
  203. - void **clear** **(** **)**
  204. Clear the animation (clear all tracks and reset all).