class_spriteframes.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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/SpriteFrames.xml.
  6. .. _class_SpriteFrames:
  7. SpriteFrames
  8. ============
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Sprite frame library for AnimatedSprite2D and AnimatedSprite3D.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Sprite frame library for an :ref:`AnimatedSprite2D<class_AnimatedSprite2D>` or :ref:`AnimatedSprite3D<class_AnimatedSprite3D>` node. Contains frames and animation data for playback.
  15. .. rst-class:: classref-reftable-group
  16. Methods
  17. -------
  18. .. table::
  19. :widths: auto
  20. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | void | :ref:`add_animation<class_SpriteFrames_method_add_animation>` **(** :ref:`StringName<class_StringName>` anim **)** |
  22. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | void | :ref:`add_frame<class_SpriteFrames_method_add_frame>` **(** :ref:`StringName<class_StringName>` anim, :ref:`Texture2D<class_Texture2D>` texture, :ref:`float<class_float>` duration=1.0, :ref:`int<class_int>` at_position=-1 **)** |
  24. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | void | :ref:`clear<class_SpriteFrames_method_clear>` **(** :ref:`StringName<class_StringName>` anim **)** |
  26. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`clear_all<class_SpriteFrames_method_clear_all>` **(** **)** |
  28. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`bool<class_bool>` | :ref:`get_animation_loop<class_SpriteFrames_method_get_animation_loop>` **(** :ref:`StringName<class_StringName>` anim **)** |const| |
  30. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_animation_names<class_SpriteFrames_method_get_animation_names>` **(** **)** |const| |
  32. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`float<class_float>` | :ref:`get_animation_speed<class_SpriteFrames_method_get_animation_speed>` **(** :ref:`StringName<class_StringName>` anim **)** |const| |
  34. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`int<class_int>` | :ref:`get_frame_count<class_SpriteFrames_method_get_frame_count>` **(** :ref:`StringName<class_StringName>` anim **)** |const| |
  36. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`float<class_float>` | :ref:`get_frame_duration<class_SpriteFrames_method_get_frame_duration>` **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx **)** |const| |
  38. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Texture2D<class_Texture2D>` | :ref:`get_frame_texture<class_SpriteFrames_method_get_frame_texture>` **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx **)** |const| |
  40. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`bool<class_bool>` | :ref:`has_animation<class_SpriteFrames_method_has_animation>` **(** :ref:`StringName<class_StringName>` anim **)** |const| |
  42. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`remove_animation<class_SpriteFrames_method_remove_animation>` **(** :ref:`StringName<class_StringName>` anim **)** |
  44. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`remove_frame<class_SpriteFrames_method_remove_frame>` **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx **)** |
  46. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`rename_animation<class_SpriteFrames_method_rename_animation>` **(** :ref:`StringName<class_StringName>` anim, :ref:`StringName<class_StringName>` newname **)** |
  48. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`set_animation_loop<class_SpriteFrames_method_set_animation_loop>` **(** :ref:`StringName<class_StringName>` anim, :ref:`bool<class_bool>` loop **)** |
  50. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`set_animation_speed<class_SpriteFrames_method_set_animation_speed>` **(** :ref:`StringName<class_StringName>` anim, :ref:`float<class_float>` fps **)** |
  52. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`set_frame<class_SpriteFrames_method_set_frame>` **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx, :ref:`Texture2D<class_Texture2D>` texture, :ref:`float<class_float>` duration=1.0 **)** |
  54. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. .. rst-class:: classref-section-separator
  56. ----
  57. .. rst-class:: classref-descriptions-group
  58. Method Descriptions
  59. -------------------
  60. .. _class_SpriteFrames_method_add_animation:
  61. .. rst-class:: classref-method
  62. void **add_animation** **(** :ref:`StringName<class_StringName>` anim **)**
  63. Adds a new ``anim`` animation to the library.
  64. .. rst-class:: classref-item-separator
  65. ----
  66. .. _class_SpriteFrames_method_add_frame:
  67. .. rst-class:: classref-method
  68. void **add_frame** **(** :ref:`StringName<class_StringName>` anim, :ref:`Texture2D<class_Texture2D>` texture, :ref:`float<class_float>` duration=1.0, :ref:`int<class_int>` at_position=-1 **)**
  69. Adds a frame to the ``anim`` animation. If ``at_position`` is ``-1``, the frame will be added to the end of the animation.
  70. .. rst-class:: classref-item-separator
  71. ----
  72. .. _class_SpriteFrames_method_clear:
  73. .. rst-class:: classref-method
  74. void **clear** **(** :ref:`StringName<class_StringName>` anim **)**
  75. Removes all frames from the ``anim`` animation.
  76. .. rst-class:: classref-item-separator
  77. ----
  78. .. _class_SpriteFrames_method_clear_all:
  79. .. rst-class:: classref-method
  80. void **clear_all** **(** **)**
  81. Removes all animations. An empty ``default`` animation will be created.
  82. .. rst-class:: classref-item-separator
  83. ----
  84. .. _class_SpriteFrames_method_get_animation_loop:
  85. .. rst-class:: classref-method
  86. :ref:`bool<class_bool>` **get_animation_loop** **(** :ref:`StringName<class_StringName>` anim **)** |const|
  87. Returns ``true`` if the given animation is configured to loop when it finishes playing. Otherwise, returns ``false``.
  88. .. rst-class:: classref-item-separator
  89. ----
  90. .. _class_SpriteFrames_method_get_animation_names:
  91. .. rst-class:: classref-method
  92. :ref:`PackedStringArray<class_PackedStringArray>` **get_animation_names** **(** **)** |const|
  93. Returns an array containing the names associated to each animation. Values are placed in alphabetical order.
  94. .. rst-class:: classref-item-separator
  95. ----
  96. .. _class_SpriteFrames_method_get_animation_speed:
  97. .. rst-class:: classref-method
  98. :ref:`float<class_float>` **get_animation_speed** **(** :ref:`StringName<class_StringName>` anim **)** |const|
  99. Returns the speed in frames per second for the ``anim`` animation.
  100. .. rst-class:: classref-item-separator
  101. ----
  102. .. _class_SpriteFrames_method_get_frame_count:
  103. .. rst-class:: classref-method
  104. :ref:`int<class_int>` **get_frame_count** **(** :ref:`StringName<class_StringName>` anim **)** |const|
  105. Returns the number of frames for the ``anim`` animation.
  106. .. rst-class:: classref-item-separator
  107. ----
  108. .. _class_SpriteFrames_method_get_frame_duration:
  109. .. rst-class:: classref-method
  110. :ref:`float<class_float>` **get_frame_duration** **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx **)** |const|
  111. Returns a relative duration of the frame ``idx`` in the ``anim`` animation (defaults to ``1.0``). For example, a frame with a duration of ``2.0`` is displayed twice as long as a frame with a duration of ``1.0``. You can calculate the absolute duration (in seconds) of a frame using the following formula:
  112. ::
  113. absolute_duration = relative_duration / (animation_fps * abs(playing_speed))
  114. In this example, ``playing_speed`` refers to either :ref:`AnimatedSprite2D.get_playing_speed<class_AnimatedSprite2D_method_get_playing_speed>` or :ref:`AnimatedSprite3D.get_playing_speed<class_AnimatedSprite3D_method_get_playing_speed>`.
  115. .. rst-class:: classref-item-separator
  116. ----
  117. .. _class_SpriteFrames_method_get_frame_texture:
  118. .. rst-class:: classref-method
  119. :ref:`Texture2D<class_Texture2D>` **get_frame_texture** **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx **)** |const|
  120. Returns the texture of the frame ``idx`` in the ``anim`` animation.
  121. .. rst-class:: classref-item-separator
  122. ----
  123. .. _class_SpriteFrames_method_has_animation:
  124. .. rst-class:: classref-method
  125. :ref:`bool<class_bool>` **has_animation** **(** :ref:`StringName<class_StringName>` anim **)** |const|
  126. Returns ``true`` if the ``anim`` animation exists.
  127. .. rst-class:: classref-item-separator
  128. ----
  129. .. _class_SpriteFrames_method_remove_animation:
  130. .. rst-class:: classref-method
  131. void **remove_animation** **(** :ref:`StringName<class_StringName>` anim **)**
  132. Removes the ``anim`` animation.
  133. .. rst-class:: classref-item-separator
  134. ----
  135. .. _class_SpriteFrames_method_remove_frame:
  136. .. rst-class:: classref-method
  137. void **remove_frame** **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx **)**
  138. Removes the ``anim`` animation's frame ``idx``.
  139. .. rst-class:: classref-item-separator
  140. ----
  141. .. _class_SpriteFrames_method_rename_animation:
  142. .. rst-class:: classref-method
  143. void **rename_animation** **(** :ref:`StringName<class_StringName>` anim, :ref:`StringName<class_StringName>` newname **)**
  144. Changes the ``anim`` animation's name to ``newname``.
  145. .. rst-class:: classref-item-separator
  146. ----
  147. .. _class_SpriteFrames_method_set_animation_loop:
  148. .. rst-class:: classref-method
  149. void **set_animation_loop** **(** :ref:`StringName<class_StringName>` anim, :ref:`bool<class_bool>` loop **)**
  150. If ``loop`` is ``true``, the ``anim`` animation will loop when it reaches the end, or the start if it is played in reverse.
  151. .. rst-class:: classref-item-separator
  152. ----
  153. .. _class_SpriteFrames_method_set_animation_speed:
  154. .. rst-class:: classref-method
  155. void **set_animation_speed** **(** :ref:`StringName<class_StringName>` anim, :ref:`float<class_float>` fps **)**
  156. Sets the speed for the ``anim`` animation in frames per second.
  157. .. rst-class:: classref-item-separator
  158. ----
  159. .. _class_SpriteFrames_method_set_frame:
  160. .. rst-class:: classref-method
  161. void **set_frame** **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx, :ref:`Texture2D<class_Texture2D>` texture, :ref:`float<class_float>` duration=1.0 **)**
  162. Sets the ``texture`` and the ``duration`` of the frame ``idx`` in the ``anim`` animation.
  163. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  164. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  165. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  166. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  167. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  168. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  169. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`