class_animatedsprite2d.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. After setting up :ref:`frames<class_AnimatedSprite2D_property_frames>`, :ref:`play<class_AnimatedSprite2D_method_play>` may be called. It's also possible to select an :ref:`animation<class_AnimatedSprite2D_property_animation>` and toggle :ref:`playing<class_AnimatedSprite2D_property_playing>`, even within the editor.
  16. To pause the current animation, call :ref:`stop<class_AnimatedSprite2D_method_stop>` or set :ref:`playing<class_AnimatedSprite2D_property_playing>` to ``false``. Alternatively, setting :ref:`speed_scale<class_AnimatedSprite2D_property_speed_scale>` to ``0`` also preserves the current frame's elapsed time.
  17. \ **Note:** You can associate a set of normal or specular maps by creating additional :ref:`SpriteFrames<class_SpriteFrames>` resources with a ``_normal`` or ``_specular`` suffix. For example, having 3 :ref:`SpriteFrames<class_SpriteFrames>` resources ``run``, ``run_normal``, and ``run_specular`` will make it so the ``run`` animation uses normal and specular maps.
  18. .. rst-class:: classref-introduction-group
  19. Tutorials
  20. ---------
  21. - :doc:`2D Sprite animation <../tutorials/2d/2d_sprite_animation>`
  22. - `2D Dodge The Creeps Demo <https://godotengine.org/asset-library/asset/515>`__
  23. .. rst-class:: classref-reftable-group
  24. Properties
  25. ----------
  26. .. table::
  27. :widths: auto
  28. +-----------------------------------------+-----------------------------------------------------------------+-------------------+
  29. | :ref:`StringName<class_StringName>` | :ref:`animation<class_AnimatedSprite2D_property_animation>` | ``&"default"`` |
  30. +-----------------------------------------+-----------------------------------------------------------------+-------------------+
  31. | :ref:`bool<class_bool>` | :ref:`centered<class_AnimatedSprite2D_property_centered>` | ``true`` |
  32. +-----------------------------------------+-----------------------------------------------------------------+-------------------+
  33. | :ref:`bool<class_bool>` | :ref:`flip_h<class_AnimatedSprite2D_property_flip_h>` | ``false`` |
  34. +-----------------------------------------+-----------------------------------------------------------------+-------------------+
  35. | :ref:`bool<class_bool>` | :ref:`flip_v<class_AnimatedSprite2D_property_flip_v>` | ``false`` |
  36. +-----------------------------------------+-----------------------------------------------------------------+-------------------+
  37. | :ref:`int<class_int>` | :ref:`frame<class_AnimatedSprite2D_property_frame>` | ``0`` |
  38. +-----------------------------------------+-----------------------------------------------------------------+-------------------+
  39. | :ref:`SpriteFrames<class_SpriteFrames>` | :ref:`frames<class_AnimatedSprite2D_property_frames>` | |
  40. +-----------------------------------------+-----------------------------------------------------------------+-------------------+
  41. | :ref:`Vector2<class_Vector2>` | :ref:`offset<class_AnimatedSprite2D_property_offset>` | ``Vector2(0, 0)`` |
  42. +-----------------------------------------+-----------------------------------------------------------------+-------------------+
  43. | :ref:`bool<class_bool>` | :ref:`playing<class_AnimatedSprite2D_property_playing>` | ``false`` |
  44. +-----------------------------------------+-----------------------------------------------------------------+-------------------+
  45. | :ref:`float<class_float>` | :ref:`speed_scale<class_AnimatedSprite2D_property_speed_scale>` | ``1.0`` |
  46. +-----------------------------------------+-----------------------------------------------------------------+-------------------+
  47. .. rst-class:: classref-reftable-group
  48. Methods
  49. -------
  50. .. table::
  51. :widths: auto
  52. +------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`play<class_AnimatedSprite2D_method_play>` **(** :ref:`StringName<class_StringName>` anim=&"", :ref:`bool<class_bool>` backwards=false **)** |
  54. +------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`stop<class_AnimatedSprite2D_method_stop>` **(** **)** |
  56. +------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  57. .. rst-class:: classref-section-separator
  58. ----
  59. .. rst-class:: classref-descriptions-group
  60. Signals
  61. -------
  62. .. _class_AnimatedSprite2D_signal_animation_finished:
  63. .. rst-class:: classref-signal
  64. **animation_finished** **(** **)**
  65. Emitted when the animation is finished (when it plays the last frame). If the animation is looping, this signal is emitted every time the last frame is drawn.
  66. .. rst-class:: classref-item-separator
  67. ----
  68. .. _class_AnimatedSprite2D_signal_frame_changed:
  69. .. rst-class:: classref-signal
  70. **frame_changed** **(** **)**
  71. Emitted when :ref:`frame<class_AnimatedSprite2D_property_frame>` changed.
  72. .. rst-class:: classref-section-separator
  73. ----
  74. .. rst-class:: classref-descriptions-group
  75. Property Descriptions
  76. ---------------------
  77. .. _class_AnimatedSprite2D_property_animation:
  78. .. rst-class:: classref-property
  79. :ref:`StringName<class_StringName>` **animation** = ``&"default"``
  80. .. rst-class:: classref-property-setget
  81. - void **set_animation** **(** :ref:`StringName<class_StringName>` value **)**
  82. - :ref:`StringName<class_StringName>` **get_animation** **(** **)**
  83. The current animation from the :ref:`frames<class_AnimatedSprite2D_property_frames>` resource. If this value changes, the ``frame`` counter is reset.
  84. .. rst-class:: classref-item-separator
  85. ----
  86. .. _class_AnimatedSprite2D_property_centered:
  87. .. rst-class:: classref-property
  88. :ref:`bool<class_bool>` **centered** = ``true``
  89. .. rst-class:: classref-property-setget
  90. - void **set_centered** **(** :ref:`bool<class_bool>` value **)**
  91. - :ref:`bool<class_bool>` **is_centered** **(** **)**
  92. If ``true``, texture will be centered.
  93. .. rst-class:: classref-item-separator
  94. ----
  95. .. _class_AnimatedSprite2D_property_flip_h:
  96. .. rst-class:: classref-property
  97. :ref:`bool<class_bool>` **flip_h** = ``false``
  98. .. rst-class:: classref-property-setget
  99. - void **set_flip_h** **(** :ref:`bool<class_bool>` value **)**
  100. - :ref:`bool<class_bool>` **is_flipped_h** **(** **)**
  101. If ``true``, texture is flipped horizontally.
  102. .. rst-class:: classref-item-separator
  103. ----
  104. .. _class_AnimatedSprite2D_property_flip_v:
  105. .. rst-class:: classref-property
  106. :ref:`bool<class_bool>` **flip_v** = ``false``
  107. .. rst-class:: classref-property-setget
  108. - void **set_flip_v** **(** :ref:`bool<class_bool>` value **)**
  109. - :ref:`bool<class_bool>` **is_flipped_v** **(** **)**
  110. If ``true``, texture is flipped vertically.
  111. .. rst-class:: classref-item-separator
  112. ----
  113. .. _class_AnimatedSprite2D_property_frame:
  114. .. rst-class:: classref-property
  115. :ref:`int<class_int>` **frame** = ``0``
  116. .. rst-class:: classref-property-setget
  117. - void **set_frame** **(** :ref:`int<class_int>` value **)**
  118. - :ref:`int<class_int>` **get_frame** **(** **)**
  119. The displayed animation frame's index.
  120. .. rst-class:: classref-item-separator
  121. ----
  122. .. _class_AnimatedSprite2D_property_frames:
  123. .. rst-class:: classref-property
  124. :ref:`SpriteFrames<class_SpriteFrames>` **frames**
  125. .. rst-class:: classref-property-setget
  126. - void **set_sprite_frames** **(** :ref:`SpriteFrames<class_SpriteFrames>` value **)**
  127. - :ref:`SpriteFrames<class_SpriteFrames>` **get_sprite_frames** **(** **)**
  128. 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.
  129. .. rst-class:: classref-item-separator
  130. ----
  131. .. _class_AnimatedSprite2D_property_offset:
  132. .. rst-class:: classref-property
  133. :ref:`Vector2<class_Vector2>` **offset** = ``Vector2(0, 0)``
  134. .. rst-class:: classref-property-setget
  135. - void **set_offset** **(** :ref:`Vector2<class_Vector2>` value **)**
  136. - :ref:`Vector2<class_Vector2>` **get_offset** **(** **)**
  137. The texture's drawing offset.
  138. .. rst-class:: classref-item-separator
  139. ----
  140. .. _class_AnimatedSprite2D_property_playing:
  141. .. rst-class:: classref-property
  142. :ref:`bool<class_bool>` **playing** = ``false``
  143. .. rst-class:: classref-property-setget
  144. - void **set_playing** **(** :ref:`bool<class_bool>` value **)**
  145. - :ref:`bool<class_bool>` **is_playing** **(** **)**
  146. If ``true``, the :ref:`animation<class_AnimatedSprite2D_property_animation>` is currently playing. Setting this property to ``false`` is the equivalent of calling :ref:`stop<class_AnimatedSprite2D_method_stop>`.
  147. .. rst-class:: classref-item-separator
  148. ----
  149. .. _class_AnimatedSprite2D_property_speed_scale:
  150. .. rst-class:: classref-property
  151. :ref:`float<class_float>` **speed_scale** = ``1.0``
  152. .. rst-class:: classref-property-setget
  153. - void **set_speed_scale** **(** :ref:`float<class_float>` value **)**
  154. - :ref:`float<class_float>` **get_speed_scale** **(** **)**
  155. The animation speed is multiplied by this value. If set to a negative value, the animation is played in reverse. If set to ``0``, the animation is paused, preserving the current frame's elapsed time.
  156. .. rst-class:: classref-section-separator
  157. ----
  158. .. rst-class:: classref-descriptions-group
  159. Method Descriptions
  160. -------------------
  161. .. _class_AnimatedSprite2D_method_play:
  162. .. rst-class:: classref-method
  163. void **play** **(** :ref:`StringName<class_StringName>` anim=&"", :ref:`bool<class_bool>` backwards=false **)**
  164. Plays the animation named ``anim``. If no ``anim`` is provided, the current animation is played. If ``backwards`` is ``true``, the animation is played in reverse.
  165. .. rst-class:: classref-item-separator
  166. ----
  167. .. _class_AnimatedSprite2D_method_stop:
  168. .. rst-class:: classref-method
  169. void **stop** **(** **)**
  170. Stops the current :ref:`animation<class_AnimatedSprite2D_property_animation>` at the current :ref:`frame<class_AnimatedSprite2D_property_frame>`.
  171. \ **Note:** This method resets the current frame's elapsed time. If this behavior is undesired, consider setting :ref:`speed_scale<class_AnimatedSprite2D_property_speed_scale>` to ``0``, instead.
  172. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  173. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  174. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  175. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  176. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  177. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`