class_animatedsprite2d.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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/2712>`__
  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>`\ (\ name\: :ref:`StringName<class_StringName>` = &"", custom_speed\: :ref:`float<class_float>` = 1.0, from_end\: :ref:`bool<class_bool>` = false\ ) |
  59. +---------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | |void| | :ref:`play_backwards<class_AnimatedSprite2D_method_play_backwards>`\ (\ name\: :ref:`StringName<class_StringName>` = &""\ ) |
  61. +---------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | |void| | :ref:`set_frame_and_progress<class_AnimatedSprite2D_method_set_frame_and_progress>`\ (\ frame\: :ref:`int<class_int>`, progress\: :ref:`float<class_float>`\ ) |
  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**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_signal_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**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_signal_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. \ **Note:** This signal is not emitted if an animation is looping.
  82. .. rst-class:: classref-item-separator
  83. ----
  84. .. _class_AnimatedSprite2D_signal_animation_looped:
  85. .. rst-class:: classref-signal
  86. **animation_looped**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_signal_animation_looped>`
  87. Emitted when the animation loops.
  88. .. rst-class:: classref-item-separator
  89. ----
  90. .. _class_AnimatedSprite2D_signal_frame_changed:
  91. .. rst-class:: classref-signal
  92. **frame_changed**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_signal_frame_changed>`
  93. Emitted when :ref:`frame<class_AnimatedSprite2D_property_frame>` changes.
  94. .. rst-class:: classref-item-separator
  95. ----
  96. .. _class_AnimatedSprite2D_signal_sprite_frames_changed:
  97. .. rst-class:: classref-signal
  98. **sprite_frames_changed**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_signal_sprite_frames_changed>`
  99. Emitted when :ref:`sprite_frames<class_AnimatedSprite2D_property_sprite_frames>` changes.
  100. .. rst-class:: classref-section-separator
  101. ----
  102. .. rst-class:: classref-descriptions-group
  103. Property Descriptions
  104. ---------------------
  105. .. _class_AnimatedSprite2D_property_animation:
  106. .. rst-class:: classref-property
  107. :ref:`StringName<class_StringName>` **animation** = ``&"default"`` :ref:`🔗<class_AnimatedSprite2D_property_animation>`
  108. .. rst-class:: classref-property-setget
  109. - |void| **set_animation**\ (\ value\: :ref:`StringName<class_StringName>`\ )
  110. - :ref:`StringName<class_StringName>` **get_animation**\ (\ )
  111. 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.
  112. .. rst-class:: classref-item-separator
  113. ----
  114. .. _class_AnimatedSprite2D_property_autoplay:
  115. .. rst-class:: classref-property
  116. :ref:`String<class_String>` **autoplay** = ``""`` :ref:`🔗<class_AnimatedSprite2D_property_autoplay>`
  117. .. rst-class:: classref-property-setget
  118. - |void| **set_autoplay**\ (\ value\: :ref:`String<class_String>`\ )
  119. - :ref:`String<class_String>` **get_autoplay**\ (\ )
  120. The key of the animation to play when the scene loads.
  121. .. rst-class:: classref-item-separator
  122. ----
  123. .. _class_AnimatedSprite2D_property_centered:
  124. .. rst-class:: classref-property
  125. :ref:`bool<class_bool>` **centered** = ``true`` :ref:`🔗<class_AnimatedSprite2D_property_centered>`
  126. .. rst-class:: classref-property-setget
  127. - |void| **set_centered**\ (\ value\: :ref:`bool<class_bool>`\ )
  128. - :ref:`bool<class_bool>` **is_centered**\ (\ )
  129. If ``true``, texture will be centered.
  130. \ **Note:** For games with a pixel art aesthetic, textures may appear deformed when centered. This is caused by their position being between pixels. To prevent this, set this property to ``false``, or consider enabling :ref:`ProjectSettings.rendering/2d/snap/snap_2d_vertices_to_pixel<class_ProjectSettings_property_rendering/2d/snap/snap_2d_vertices_to_pixel>` and :ref:`ProjectSettings.rendering/2d/snap/snap_2d_transforms_to_pixel<class_ProjectSettings_property_rendering/2d/snap/snap_2d_transforms_to_pixel>`.
  131. .. rst-class:: classref-item-separator
  132. ----
  133. .. _class_AnimatedSprite2D_property_flip_h:
  134. .. rst-class:: classref-property
  135. :ref:`bool<class_bool>` **flip_h** = ``false`` :ref:`🔗<class_AnimatedSprite2D_property_flip_h>`
  136. .. rst-class:: classref-property-setget
  137. - |void| **set_flip_h**\ (\ value\: :ref:`bool<class_bool>`\ )
  138. - :ref:`bool<class_bool>` **is_flipped_h**\ (\ )
  139. If ``true``, texture is flipped horizontally.
  140. .. rst-class:: classref-item-separator
  141. ----
  142. .. _class_AnimatedSprite2D_property_flip_v:
  143. .. rst-class:: classref-property
  144. :ref:`bool<class_bool>` **flip_v** = ``false`` :ref:`🔗<class_AnimatedSprite2D_property_flip_v>`
  145. .. rst-class:: classref-property-setget
  146. - |void| **set_flip_v**\ (\ value\: :ref:`bool<class_bool>`\ )
  147. - :ref:`bool<class_bool>` **is_flipped_v**\ (\ )
  148. If ``true``, texture is flipped vertically.
  149. .. rst-class:: classref-item-separator
  150. ----
  151. .. _class_AnimatedSprite2D_property_frame:
  152. .. rst-class:: classref-property
  153. :ref:`int<class_int>` **frame** = ``0`` :ref:`🔗<class_AnimatedSprite2D_property_frame>`
  154. .. rst-class:: classref-property-setget
  155. - |void| **set_frame**\ (\ value\: :ref:`int<class_int>`\ )
  156. - :ref:`int<class_int>` **get_frame**\ (\ )
  157. 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>`.
  158. .. rst-class:: classref-item-separator
  159. ----
  160. .. _class_AnimatedSprite2D_property_frame_progress:
  161. .. rst-class:: classref-property
  162. :ref:`float<class_float>` **frame_progress** = ``0.0`` :ref:`🔗<class_AnimatedSprite2D_property_frame_progress>`
  163. .. rst-class:: classref-property-setget
  164. - |void| **set_frame_progress**\ (\ value\: :ref:`float<class_float>`\ )
  165. - :ref:`float<class_float>` **get_frame_progress**\ (\ )
  166. 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``.
  167. .. rst-class:: classref-item-separator
  168. ----
  169. .. _class_AnimatedSprite2D_property_offset:
  170. .. rst-class:: classref-property
  171. :ref:`Vector2<class_Vector2>` **offset** = ``Vector2(0, 0)`` :ref:`🔗<class_AnimatedSprite2D_property_offset>`
  172. .. rst-class:: classref-property-setget
  173. - |void| **set_offset**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
  174. - :ref:`Vector2<class_Vector2>` **get_offset**\ (\ )
  175. The texture's drawing offset.
  176. .. rst-class:: classref-item-separator
  177. ----
  178. .. _class_AnimatedSprite2D_property_speed_scale:
  179. .. rst-class:: classref-property
  180. :ref:`float<class_float>` **speed_scale** = ``1.0`` :ref:`🔗<class_AnimatedSprite2D_property_speed_scale>`
  181. .. rst-class:: classref-property-setget
  182. - |void| **set_speed_scale**\ (\ value\: :ref:`float<class_float>`\ )
  183. - :ref:`float<class_float>` **get_speed_scale**\ (\ )
  184. 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.
  185. If set to a negative value, the animation is played in reverse. If set to ``0``, the animation will not advance.
  186. .. rst-class:: classref-item-separator
  187. ----
  188. .. _class_AnimatedSprite2D_property_sprite_frames:
  189. .. rst-class:: classref-property
  190. :ref:`SpriteFrames<class_SpriteFrames>` **sprite_frames** :ref:`🔗<class_AnimatedSprite2D_property_sprite_frames>`
  191. .. rst-class:: classref-property-setget
  192. - |void| **set_sprite_frames**\ (\ value\: :ref:`SpriteFrames<class_SpriteFrames>`\ )
  193. - :ref:`SpriteFrames<class_SpriteFrames>` **get_sprite_frames**\ (\ )
  194. 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.
  195. .. rst-class:: classref-section-separator
  196. ----
  197. .. rst-class:: classref-descriptions-group
  198. Method Descriptions
  199. -------------------
  200. .. _class_AnimatedSprite2D_method_get_playing_speed:
  201. .. rst-class:: classref-method
  202. :ref:`float<class_float>` **get_playing_speed**\ (\ ) |const| :ref:`🔗<class_AnimatedSprite2D_method_get_playing_speed>`
  203. 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.
  204. Returns a negative value if the current animation is playing backwards.
  205. .. rst-class:: classref-item-separator
  206. ----
  207. .. _class_AnimatedSprite2D_method_is_playing:
  208. .. rst-class:: classref-method
  209. :ref:`bool<class_bool>` **is_playing**\ (\ ) |const| :ref:`🔗<class_AnimatedSprite2D_method_is_playing>`
  210. Returns ``true`` if an animation is currently playing (even if :ref:`speed_scale<class_AnimatedSprite2D_property_speed_scale>` and/or ``custom_speed`` are ``0``).
  211. .. rst-class:: classref-item-separator
  212. ----
  213. .. _class_AnimatedSprite2D_method_pause:
  214. .. rst-class:: classref-method
  215. |void| **pause**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_method_pause>`
  216. 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.
  217. See also :ref:`stop()<class_AnimatedSprite2D_method_stop>`.
  218. .. rst-class:: classref-item-separator
  219. ----
  220. .. _class_AnimatedSprite2D_method_play:
  221. .. rst-class:: classref-method
  222. |void| **play**\ (\ name\: :ref:`StringName<class_StringName>` = &"", custom_speed\: :ref:`float<class_float>` = 1.0, from_end\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_AnimatedSprite2D_method_play>`
  223. 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>`).
  224. 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.
  225. .. rst-class:: classref-item-separator
  226. ----
  227. .. _class_AnimatedSprite2D_method_play_backwards:
  228. .. rst-class:: classref-method
  229. |void| **play_backwards**\ (\ name\: :ref:`StringName<class_StringName>` = &""\ ) :ref:`🔗<class_AnimatedSprite2D_method_play_backwards>`
  230. Plays the animation with key ``name`` in reverse.
  231. 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.
  232. .. rst-class:: classref-item-separator
  233. ----
  234. .. _class_AnimatedSprite2D_method_set_frame_and_progress:
  235. .. rst-class:: classref-method
  236. |void| **set_frame_and_progress**\ (\ frame\: :ref:`int<class_int>`, progress\: :ref:`float<class_float>`\ ) :ref:`🔗<class_AnimatedSprite2D_method_set_frame_and_progress>`
  237. Sets :ref:`frame<class_AnimatedSprite2D_property_frame>` the :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>` to the given values. Unlike setting :ref:`frame<class_AnimatedSprite2D_property_frame>`, this method does not reset the :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>` to ``0.0`` implicitly.
  238. \ **Example:** Change the animation while keeping the same :ref:`frame<class_AnimatedSprite2D_property_frame>` and :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>`:
  239. .. tabs::
  240. .. code-tab:: gdscript
  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**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_method_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.)`
  258. .. |void| replace:: :abbr:`void (No return value.)`