AnimatedSprite2D.xml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="AnimatedSprite2D" inherits="Node2D" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
  3. <brief_description>
  4. Sprite node that contains multiple textures as frames to play for animation.
  5. </brief_description>
  6. <description>
  7. [AnimatedSprite2D] is similar to the [Sprite2D] node, except it carries multiple textures as animation frames. Animations are created using a [SpriteFrames] resource, which allows you to import image files (or a folder containing said files) to provide the animation frames for the sprite. The [SpriteFrames] resource can be configured in the editor via the SpriteFrames bottom panel.
  8. </description>
  9. <tutorials>
  10. <link title="2D Sprite animation">$DOCS_URL/tutorials/2d/2d_sprite_animation.html</link>
  11. <link title="2D Dodge The Creeps Demo">https://godotengine.org/asset-library/asset/515</link>
  12. </tutorials>
  13. <methods>
  14. <method name="get_playing_speed" qualifiers="const">
  15. <return type="float" />
  16. <description>
  17. Returns the actual playing speed of current animation or [code]0[/code] if not playing. This speed is the [member speed_scale] property multiplied by [code]custom_speed[/code] argument specified when calling the [method play] method.
  18. Returns a negative value if the current animation is playing backwards.
  19. </description>
  20. </method>
  21. <method name="is_playing" qualifiers="const">
  22. <return type="bool" />
  23. <description>
  24. Returns [code]true[/code] if an animation is currently playing (even if [member speed_scale] and/or [code]custom_speed[/code] are [code]0[/code]).
  25. </description>
  26. </method>
  27. <method name="pause">
  28. <return type="void" />
  29. <description>
  30. Pauses the currently playing animation. The [member frame] and [member frame_progress] will be kept and calling [method play] or [method play_backwards] without arguments will resume the animation from the current playback position.
  31. See also [method stop].
  32. </description>
  33. </method>
  34. <method name="play">
  35. <return type="void" />
  36. <param index="0" name="name" type="StringName" default="&amp;&quot;&quot;" />
  37. <param index="1" name="custom_speed" type="float" default="1.0" />
  38. <param index="2" name="from_end" type="bool" default="false" />
  39. <description>
  40. Plays the animation with key [param name]. If [param custom_speed] is negative and [param from_end] is [code]true[/code], the animation will play backwards (which is equivalent to calling [method play_backwards]).
  41. If this method is called with that same animation [param name], or with no [param name] parameter, the assigned animation will resume playing if it was paused.
  42. </description>
  43. </method>
  44. <method name="play_backwards">
  45. <return type="void" />
  46. <param index="0" name="name" type="StringName" default="&amp;&quot;&quot;" />
  47. <description>
  48. Plays the animation with key [param name] in reverse.
  49. This method is a shorthand for [method play] with [code]custom_speed = -1.0[/code] and [code]from_end = true[/code], so see its description for more information.
  50. </description>
  51. </method>
  52. <method name="set_frame_and_progress">
  53. <return type="void" />
  54. <param index="0" name="frame" type="int" />
  55. <param index="1" name="progress" type="float" />
  56. <description>
  57. The setter of [member frame] resets the [member frame_progress] to [code]0.0[/code] implicitly, but this method avoids that.
  58. This is useful when you want to carry over the current [member frame_progress] to another [member frame].
  59. [b]Example:[/b]
  60. [codeblocks]
  61. [gdscript]
  62. # Change the animation with keeping the frame index and progress.
  63. var current_frame = animated_sprite.get_frame()
  64. var current_progress = animated_sprite.get_frame_progress()
  65. animated_sprite.play("walk_another_skin")
  66. animated_sprite.set_frame_and_progress(current_frame, current_progress)
  67. [/gdscript]
  68. [/codeblocks]
  69. </description>
  70. </method>
  71. <method name="stop">
  72. <return type="void" />
  73. <description>
  74. Stops the currently playing animation. The animation position is reset to [code]0[/code] and the [code]custom_speed[/code] is reset to [code]1.0[/code]. See also [method pause].
  75. </description>
  76. </method>
  77. </methods>
  78. <members>
  79. <member name="animation" type="StringName" setter="set_animation" getter="get_animation" default="&amp;&quot;default&quot;">
  80. The current animation from the [member sprite_frames] resource. If this value is changed, the [member frame] counter and the [member frame_progress] are reset.
  81. </member>
  82. <member name="autoplay" type="String" setter="set_autoplay" getter="get_autoplay" default="&quot;&quot;">
  83. The key of the animation to play when the scene loads.
  84. </member>
  85. <member name="centered" type="bool" setter="set_centered" getter="is_centered" default="true">
  86. If [code]true[/code], texture will be centered.
  87. </member>
  88. <member name="flip_h" type="bool" setter="set_flip_h" getter="is_flipped_h" default="false">
  89. If [code]true[/code], texture is flipped horizontally.
  90. </member>
  91. <member name="flip_v" type="bool" setter="set_flip_v" getter="is_flipped_v" default="false">
  92. If [code]true[/code], texture is flipped vertically.
  93. </member>
  94. <member name="frame" type="int" setter="set_frame" getter="get_frame" default="0">
  95. The displayed animation frame's index. Setting this property also resets [member frame_progress]. If this is not desired, use [method set_frame_and_progress].
  96. </member>
  97. <member name="frame_progress" type="float" setter="set_frame_progress" getter="get_frame_progress" default="0.0">
  98. The progress value between [code]0.0[/code] and [code]1.0[/code] until the current frame transitions to the next frame. If the animation is playing backwards, the value transitions from [code]1.0[/code] to [code]0.0[/code].
  99. </member>
  100. <member name="offset" type="Vector2" setter="set_offset" getter="get_offset" default="Vector2(0, 0)">
  101. The texture's drawing offset.
  102. </member>
  103. <member name="speed_scale" type="float" setter="set_speed_scale" getter="get_speed_scale" default="1.0">
  104. The speed scaling ratio. For example, if this value is [code]1[/code], then the animation plays at normal speed. If it's [code]0.5[/code], then it plays at half speed. If it's [code]2[/code], then it plays at double speed.
  105. If set to a negative value, the animation is played in reverse. If set to [code]0[/code], the animation will not advance.
  106. </member>
  107. <member name="sprite_frames" type="SpriteFrames" setter="set_sprite_frames" getter="get_sprite_frames">
  108. The [SpriteFrames] resource containing the animation(s). Allows you the option to load, edit, clear, make unique and save the states of the [SpriteFrames] resource.
  109. </member>
  110. </members>
  111. <signals>
  112. <signal name="animation_changed">
  113. <description>
  114. Emitted when [member animation] changes.
  115. </description>
  116. </signal>
  117. <signal name="animation_finished">
  118. <description>
  119. Emitted when the animation reaches the end, or the start if it is played in reverse. When the animation finishes, it pauses the playback.
  120. </description>
  121. </signal>
  122. <signal name="animation_looped">
  123. <description>
  124. Emitted when the animation loops.
  125. </description>
  126. </signal>
  127. <signal name="frame_changed">
  128. <description>
  129. Emitted when [member frame] changes.
  130. </description>
  131. </signal>
  132. <signal name="sprite_frames_changed">
  133. <description>
  134. Emitted when [member sprite_frames] changes.
  135. </description>
  136. </signal>
  137. </signals>
  138. </class>