class_animatedsprite2d.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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/AnimatedSprite2D.xml.
  6. .. _class_AnimatedSprite2D:
  7. AnimatedSprite2D
  8. ================
  9. **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. Sprite node that contains multiple textures as frames to play for animation.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. **AnimatedSprite2D** is similar to the :ref:`Sprite2D<class_Sprite2D>` node, except it carries multiple textures as animation frames. Animations are created using a :ref:`SpriteFrames<class_SpriteFrames>` resource, which allows you to import image files (or a folder containing said files) to provide the animation frames for the sprite. The :ref:`SpriteFrames<class_SpriteFrames>` resource can be configured in the editor via the SpriteFrames bottom panel.
  15. .. rst-class:: classref-introduction-group
  16. Tutorials
  17. ---------
  18. - :doc:`2D Sprite animation <../tutorials/2d/2d_sprite_animation>`
  19. - `2D Dodge The Creeps Demo <https://godotengine.org/asset-library/asset/515>`__
  20. .. rst-class:: classref-reftable-group
  21. Properties
  22. ----------
  23. .. table::
  24. :widths: auto
  25. +-----------------------------------------+-----------------------------------------------------------------------+-------------------+
  26. | :ref:`StringName<class_StringName>` | :ref:`animation<class_AnimatedSprite2D_property_animation>` | ``&"default"`` |
  27. +-----------------------------------------+-----------------------------------------------------------------------+-------------------+
  28. | :ref:`String<class_String>` | :ref:`autoplay<class_AnimatedSprite2D_property_autoplay>` | ``""`` |
  29. +-----------------------------------------+-----------------------------------------------------------------------+-------------------+
  30. | :ref:`bool<class_bool>` | :ref:`centered<class_AnimatedSprite2D_property_centered>` | ``true`` |
  31. +-----------------------------------------+-----------------------------------------------------------------------+-------------------+
  32. | :ref:`bool<class_bool>` | :ref:`flip_h<class_AnimatedSprite2D_property_flip_h>` | ``false`` |
  33. +-----------------------------------------+-----------------------------------------------------------------------+-------------------+
  34. | :ref:`bool<class_bool>` | :ref:`flip_v<class_AnimatedSprite2D_property_flip_v>` | ``false`` |
  35. +-----------------------------------------+-----------------------------------------------------------------------+-------------------+
  36. | :ref:`int<class_int>` | :ref:`frame<class_AnimatedSprite2D_property_frame>` | ``0`` |
  37. +-----------------------------------------+-----------------------------------------------------------------------+-------------------+
  38. | :ref:`float<class_float>` | :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>` | ``0.0`` |
  39. +-----------------------------------------+-----------------------------------------------------------------------+-------------------+
  40. | :ref:`Vector2<class_Vector2>` | :ref:`offset<class_AnimatedSprite2D_property_offset>` | ``Vector2(0, 0)`` |
  41. +-----------------------------------------+-----------------------------------------------------------------------+-------------------+
  42. | :ref:`float<class_float>` | :ref:`speed_scale<class_AnimatedSprite2D_property_speed_scale>` | ``1.0`` |
  43. +-----------------------------------------+-----------------------------------------------------------------------+-------------------+
  44. | :ref:`SpriteFrames<class_SpriteFrames>` | :ref:`sprite_frames<class_AnimatedSprite2D_property_sprite_frames>` | |
  45. +-----------------------------------------+-----------------------------------------------------------------------+-------------------+
  46. .. rst-class:: classref-reftable-group
  47. Methods
  48. -------
  49. .. table::
  50. :widths: auto
  51. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`float<class_float>` | :ref:`get_playing_speed<class_AnimatedSprite2D_method_get_playing_speed>` **(** **)** |const| |
  53. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`bool<class_bool>` | :ref:`is_playing<class_AnimatedSprite2D_method_is_playing>` **(** **)** |const| |
  55. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | void | :ref:`pause<class_AnimatedSprite2D_method_pause>` **(** **)** |
  57. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`play<class_AnimatedSprite2D_method_play>` **(** :ref:`StringName<class_StringName>` name=&"", :ref:`float<class_float>` custom_speed=1.0, :ref:`bool<class_bool>` from_end=false **)** |
  59. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`play_backwards<class_AnimatedSprite2D_method_play_backwards>` **(** :ref:`StringName<class_StringName>` name=&"" **)** |
  61. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`set_frame_and_progress<class_AnimatedSprite2D_method_set_frame_and_progress>` **(** :ref:`int<class_int>` frame, :ref:`float<class_float>` progress **)** |
  63. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`stop<class_AnimatedSprite2D_method_stop>` **(** **)** |
  65. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. .. rst-class:: classref-section-separator
  67. ----
  68. .. rst-class:: classref-descriptions-group
  69. Signals
  70. -------
  71. .. _class_AnimatedSprite2D_signal_animation_changed:
  72. .. rst-class:: classref-signal
  73. **animation_changed** **(** **)**
  74. Emitted when :ref:`animation<class_AnimatedSprite2D_property_animation>` changes.
  75. .. rst-class:: classref-item-separator
  76. ----
  77. .. _class_AnimatedSprite2D_signal_animation_finished:
  78. .. rst-class:: classref-signal
  79. **animation_finished** **(** **)**
  80. Emitted when the animation reaches the end, or the start if it is played in reverse. When the animation finishes, it pauses the playback.
  81. .. rst-class:: classref-item-separator
  82. ----
  83. .. _class_AnimatedSprite2D_signal_animation_looped:
  84. .. rst-class:: classref-signal
  85. **animation_looped** **(** **)**
  86. Emitted when the animation loops.
  87. .. rst-class:: classref-item-separator
  88. ----
  89. .. _class_AnimatedSprite2D_signal_frame_changed:
  90. .. rst-class:: classref-signal
  91. **frame_changed** **(** **)**
  92. Emitted when :ref:`frame<class_AnimatedSprite2D_property_frame>` changes.
  93. .. rst-class:: classref-item-separator
  94. ----
  95. .. _class_AnimatedSprite2D_signal_sprite_frames_changed:
  96. .. rst-class:: classref-signal
  97. **sprite_frames_changed** **(** **)**
  98. Emitted when :ref:`sprite_frames<class_AnimatedSprite2D_property_sprite_frames>` changes.
  99. .. rst-class:: classref-section-separator
  100. ----
  101. .. rst-class:: classref-descriptions-group
  102. Property Descriptions
  103. ---------------------
  104. .. _class_AnimatedSprite2D_property_animation:
  105. .. rst-class:: classref-property
  106. :ref:`StringName<class_StringName>` **animation** = ``&"default"``
  107. .. rst-class:: classref-property-setget
  108. - void **set_animation** **(** :ref:`StringName<class_StringName>` value **)**
  109. - :ref:`StringName<class_StringName>` **get_animation** **(** **)**
  110. The current animation from the :ref:`sprite_frames<class_AnimatedSprite2D_property_sprite_frames>` resource. If this value is changed, the :ref:`frame<class_AnimatedSprite2D_property_frame>` counter and the :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>` are reset.
  111. .. rst-class:: classref-item-separator
  112. ----
  113. .. _class_AnimatedSprite2D_property_autoplay:
  114. .. rst-class:: classref-property
  115. :ref:`String<class_String>` **autoplay** = ``""``
  116. .. rst-class:: classref-property-setget
  117. - void **set_autoplay** **(** :ref:`String<class_String>` value **)**
  118. - :ref:`String<class_String>` **get_autoplay** **(** **)**
  119. The key of the animation to play when the scene loads.
  120. .. rst-class:: classref-item-separator
  121. ----
  122. .. _class_AnimatedSprite2D_property_centered:
  123. .. rst-class:: classref-property
  124. :ref:`bool<class_bool>` **centered** = ``true``
  125. .. rst-class:: classref-property-setget
  126. - void **set_centered** **(** :ref:`bool<class_bool>` value **)**
  127. - :ref:`bool<class_bool>` **is_centered** **(** **)**
  128. If ``true``, texture will be centered.
  129. .. rst-class:: classref-item-separator
  130. ----
  131. .. _class_AnimatedSprite2D_property_flip_h:
  132. .. rst-class:: classref-property
  133. :ref:`bool<class_bool>` **flip_h** = ``false``
  134. .. rst-class:: classref-property-setget
  135. - void **set_flip_h** **(** :ref:`bool<class_bool>` value **)**
  136. - :ref:`bool<class_bool>` **is_flipped_h** **(** **)**
  137. If ``true``, texture is flipped horizontally.
  138. .. rst-class:: classref-item-separator
  139. ----
  140. .. _class_AnimatedSprite2D_property_flip_v:
  141. .. rst-class:: classref-property
  142. :ref:`bool<class_bool>` **flip_v** = ``false``
  143. .. rst-class:: classref-property-setget
  144. - void **set_flip_v** **(** :ref:`bool<class_bool>` value **)**
  145. - :ref:`bool<class_bool>` **is_flipped_v** **(** **)**
  146. If ``true``, texture is flipped vertically.
  147. .. rst-class:: classref-item-separator
  148. ----
  149. .. _class_AnimatedSprite2D_property_frame:
  150. .. rst-class:: classref-property
  151. :ref:`int<class_int>` **frame** = ``0``
  152. .. rst-class:: classref-property-setget
  153. - void **set_frame** **(** :ref:`int<class_int>` value **)**
  154. - :ref:`int<class_int>` **get_frame** **(** **)**
  155. The displayed animation frame's index. Setting this property also resets :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>`. If this is not desired, use :ref:`set_frame_and_progress<class_AnimatedSprite2D_method_set_frame_and_progress>`.
  156. .. rst-class:: classref-item-separator
  157. ----
  158. .. _class_AnimatedSprite2D_property_frame_progress:
  159. .. rst-class:: classref-property
  160. :ref:`float<class_float>` **frame_progress** = ``0.0``
  161. .. rst-class:: classref-property-setget
  162. - void **set_frame_progress** **(** :ref:`float<class_float>` value **)**
  163. - :ref:`float<class_float>` **get_frame_progress** **(** **)**
  164. The progress value between ``0.0`` and ``1.0`` until the current frame transitions to the next frame. If the animation is playing backwards, the value transitions from ``1.0`` to ``0.0``.
  165. .. rst-class:: classref-item-separator
  166. ----
  167. .. _class_AnimatedSprite2D_property_offset:
  168. .. rst-class:: classref-property
  169. :ref:`Vector2<class_Vector2>` **offset** = ``Vector2(0, 0)``
  170. .. rst-class:: classref-property-setget
  171. - void **set_offset** **(** :ref:`Vector2<class_Vector2>` value **)**
  172. - :ref:`Vector2<class_Vector2>` **get_offset** **(** **)**
  173. The texture's drawing offset.
  174. .. rst-class:: classref-item-separator
  175. ----
  176. .. _class_AnimatedSprite2D_property_speed_scale:
  177. .. rst-class:: classref-property
  178. :ref:`float<class_float>` **speed_scale** = ``1.0``
  179. .. rst-class:: classref-property-setget
  180. - void **set_speed_scale** **(** :ref:`float<class_float>` value **)**
  181. - :ref:`float<class_float>` **get_speed_scale** **(** **)**
  182. The speed scaling ratio. For example, 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.
  183. If set to a negative value, the animation is played in reverse. If set to ``0``, the animation will not advance.
  184. .. rst-class:: classref-item-separator
  185. ----
  186. .. _class_AnimatedSprite2D_property_sprite_frames:
  187. .. rst-class:: classref-property
  188. :ref:`SpriteFrames<class_SpriteFrames>` **sprite_frames**
  189. .. rst-class:: classref-property-setget
  190. - void **set_sprite_frames** **(** :ref:`SpriteFrames<class_SpriteFrames>` value **)**
  191. - :ref:`SpriteFrames<class_SpriteFrames>` **get_sprite_frames** **(** **)**
  192. The :ref:`SpriteFrames<class_SpriteFrames>` resource containing the animation(s). Allows you the option to load, edit, clear, make unique and save the states of the :ref:`SpriteFrames<class_SpriteFrames>` resource.
  193. .. rst-class:: classref-section-separator
  194. ----
  195. .. rst-class:: classref-descriptions-group
  196. Method Descriptions
  197. -------------------
  198. .. _class_AnimatedSprite2D_method_get_playing_speed:
  199. .. rst-class:: classref-method
  200. :ref:`float<class_float>` **get_playing_speed** **(** **)** |const|
  201. Returns the actual playing speed of current animation or ``0`` if not playing. This speed is the :ref:`speed_scale<class_AnimatedSprite2D_property_speed_scale>` property multiplied by ``custom_speed`` argument specified when calling the :ref:`play<class_AnimatedSprite2D_method_play>` method.
  202. Returns a negative value if the current animation is playing backwards.
  203. .. rst-class:: classref-item-separator
  204. ----
  205. .. _class_AnimatedSprite2D_method_is_playing:
  206. .. rst-class:: classref-method
  207. :ref:`bool<class_bool>` **is_playing** **(** **)** |const|
  208. Returns ``true`` if an animation is currently playing (even if :ref:`speed_scale<class_AnimatedSprite2D_property_speed_scale>` and/or ``custom_speed`` are ``0``).
  209. .. rst-class:: classref-item-separator
  210. ----
  211. .. _class_AnimatedSprite2D_method_pause:
  212. .. rst-class:: classref-method
  213. void **pause** **(** **)**
  214. Pauses the currently playing animation. The :ref:`frame<class_AnimatedSprite2D_property_frame>` and :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>` will be kept and calling :ref:`play<class_AnimatedSprite2D_method_play>` or :ref:`play_backwards<class_AnimatedSprite2D_method_play_backwards>` without arguments will resume the animation from the current playback position.
  215. See also :ref:`stop<class_AnimatedSprite2D_method_stop>`.
  216. .. rst-class:: classref-item-separator
  217. ----
  218. .. _class_AnimatedSprite2D_method_play:
  219. .. rst-class:: classref-method
  220. void **play** **(** :ref:`StringName<class_StringName>` name=&"", :ref:`float<class_float>` custom_speed=1.0, :ref:`bool<class_bool>` from_end=false **)**
  221. Plays the animation with key ``name``. If ``custom_speed`` is negative and ``from_end`` is ``true``, the animation will play backwards (which is equivalent to calling :ref:`play_backwards<class_AnimatedSprite2D_method_play_backwards>`).
  222. If this method is called with that same animation ``name``, or with no ``name`` parameter, the assigned animation will resume playing if it was paused.
  223. .. rst-class:: classref-item-separator
  224. ----
  225. .. _class_AnimatedSprite2D_method_play_backwards:
  226. .. rst-class:: classref-method
  227. void **play_backwards** **(** :ref:`StringName<class_StringName>` name=&"" **)**
  228. Plays the animation with key ``name`` in reverse.
  229. This method is a shorthand for :ref:`play<class_AnimatedSprite2D_method_play>` with ``custom_speed = -1.0`` and ``from_end = true``, so see its description for more information.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_AnimatedSprite2D_method_set_frame_and_progress:
  233. .. rst-class:: classref-method
  234. void **set_frame_and_progress** **(** :ref:`int<class_int>` frame, :ref:`float<class_float>` progress **)**
  235. The setter of :ref:`frame<class_AnimatedSprite2D_property_frame>` resets the :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>` to ``0.0`` implicitly, but this method avoids that.
  236. This is useful when you want to carry over the current :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>` to another :ref:`frame<class_AnimatedSprite2D_property_frame>`.
  237. \ **Example:**\
  238. .. tabs::
  239. .. code-tab:: gdscript
  240. # Change the animation with keeping the frame index and progress.
  241. var current_frame = animated_sprite.get_frame()
  242. var current_progress = animated_sprite.get_frame_progress()
  243. animated_sprite.play("walk_another_skin")
  244. animated_sprite.set_frame_and_progress(current_frame, current_progress)
  245. .. rst-class:: classref-item-separator
  246. ----
  247. .. _class_AnimatedSprite2D_method_stop:
  248. .. rst-class:: classref-method
  249. void **stop** **(** **)**
  250. Stops the currently playing animation. The animation position is reset to ``0`` and the ``custom_speed`` is reset to ``1.0``. See also :ref:`pause<class_AnimatedSprite2D_method_pause>`.
  251. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  252. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  253. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  254. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  255. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  256. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  257. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`