summaryrefslogtreecommitdiff
path: root/doc/classes/AnimatedSprite2D.xml
diff options
context:
space:
mode:
Diffstat (limited to 'doc/classes/AnimatedSprite2D.xml')
-rw-r--r--doc/classes/AnimatedSprite2D.xml102
1 files changed, 82 insertions, 20 deletions
diff --git a/doc/classes/AnimatedSprite2D.xml b/doc/classes/AnimatedSprite2D.xml
index cd9c0cee98..9872c59990 100644
--- a/doc/classes/AnimatedSprite2D.xml
+++ b/doc/classes/AnimatedSprite2D.xml
@@ -5,34 +5,82 @@
</brief_description>
<description>
[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.
- After setting up [member frames], [method play] may be called. It's also possible to select an [member animation] and toggle [member playing], even within the editor.
- To pause the current animation, set [member playing] to [code]false[/code]. Alternatively, setting [member speed_scale] to [code]0[/code] also preserves the current frame's elapsed time.
</description>
<tutorials>
<link title="2D Sprite animation">$DOCS_URL/tutorials/2d/2d_sprite_animation.html</link>
<link title="2D Dodge The Creeps Demo">https://godotengine.org/asset-library/asset/515</link>
</tutorials>
<methods>
+ <method name="get_playing_speed" qualifiers="const">
+ <return type="float" />
+ <description>
+ 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.
+ Returns a negative value if the current animation is playing backwards.
+ </description>
+ </method>
+ <method name="is_playing" qualifiers="const">
+ <return type="bool" />
+ <description>
+ 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]).
+ </description>
+ </method>
+ <method name="pause">
+ <return type="void" />
+ <description>
+ 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.
+ See also [method stop].
+ </description>
+ </method>
<method name="play">
<return type="void" />
- <param index="0" name="anim" type="StringName" default="&amp;&quot;&quot;" />
- <param index="1" name="backwards" type="bool" default="false" />
+ <param index="0" name="name" type="StringName" default="&amp;&quot;&quot;" />
+ <param index="1" name="custom_speed" type="float" default="1.0" />
+ <param index="2" name="from_end" type="bool" default="false" />
+ <description>
+ 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]).
+ 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.
+ </description>
+ </method>
+ <method name="play_backwards">
+ <return type="void" />
+ <param index="0" name="name" type="StringName" default="&amp;&quot;&quot;" />
+ <description>
+ Plays the animation with key [param name] in reverse.
+ 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.
+ </description>
+ </method>
+ <method name="set_frame_and_progress">
+ <return type="void" />
+ <param index="0" name="frame" type="int" />
+ <param index="1" name="progress" type="float" />
<description>
- Plays the animation named [param anim]. If no [param anim] is provided, the current animation is played. If [param backwards] is [code]true[/code], the animation is played in reverse.
- [b]Note:[/b] If [member speed_scale] is negative, the animation direction specified by [param backwards] will be inverted.
+ The setter of [member frame] resets the [member frame_progress] to [code]0.0[/code] implicitly, but this method avoids that.
+ This is useful when you want to carry over the current [member frame_progress] to another [member frame].
+ [b]Example:[/b]
+ [codeblocks]
+ [gdscript]
+ # Change the animation with keeping the frame index and progress.
+ var current_frame = animated_sprite.get_frame()
+ var current_progress = animated_sprite.get_frame_progress()
+ animated_sprite.play("walk_another_skin")
+ animated_sprite.set_frame_and_progress(current_frame, current_progress)
+ [/gdscript]
+ [/codeblocks]
</description>
</method>
<method name="stop">
<return type="void" />
<description>
- Stops the current [member animation] at the current [member frame].
- [b]Note:[/b] This method resets the current frame's elapsed time and removes the [code]backwards[/code] flag from the current [member animation] (if it was previously set by [method play]). If this behavior is undesired, set [member playing] to [code]false[/code] instead.
+ 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].
</description>
</method>
</methods>
<members>
<member name="animation" type="StringName" setter="set_animation" getter="get_animation" default="&amp;&quot;default&quot;">
- The current animation from the [member frames] resource. If this value changes, the [code]frame[/code] counter is reset.
+ 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.
+ </member>
+ <member name="autoplay" type="String" setter="set_autoplay" getter="get_autoplay" default="&quot;&quot;">
+ The key of the animation to play when the scene loads.
</member>
<member name="centered" type="bool" setter="set_centered" getter="is_centered" default="true">
If [code]true[/code], texture will be centered.
@@ -44,32 +92,46 @@
If [code]true[/code], texture is flipped vertically.
</member>
<member name="frame" type="int" setter="set_frame" getter="get_frame" default="0">
- The displayed animation frame's index.
+ 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].
</member>
- <member name="frames" type="SpriteFrames" setter="set_sprite_frames" getter="get_sprite_frames">
- 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.
+ <member name="frame_progress" type="float" setter="set_frame_progress" getter="get_frame_progress" default="0.0">
+ 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].
</member>
<member name="offset" type="Vector2" setter="set_offset" getter="get_offset" default="Vector2(0, 0)">
The texture's drawing offset.
</member>
- <member name="playing" type="bool" setter="set_playing" getter="is_playing" default="false">
- If [code]true[/code], the [member animation] is currently playing. Setting this property to [code]false[/code] pauses the current animation. Use [method stop] to stop the animation at the current frame instead.
- [b]Note:[/b] Unlike [method stop], changing this property to [code]false[/code] preserves the current frame's elapsed time and the [code]backwards[/code] flag of the current [member animation] (if it was previously set by [method play]).
- [b]Note:[/b] After a non-looping animation finishes, the property still remains [code]true[/code].
- </member>
<member name="speed_scale" type="float" setter="set_speed_scale" getter="get_speed_scale" default="1.0">
- The animation speed is multiplied by this value. If set to a negative value, the animation is played in reverse. If set to [code]0[/code], the animation is paused, preserving the current frame's elapsed time.
+ 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.
+ If set to a negative value, the animation is played in reverse. If set to [code]0[/code], the animation will not advance.
+ </member>
+ <member name="sprite_frames" type="SpriteFrames" setter="set_sprite_frames" getter="get_sprite_frames">
+ 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.
</member>
</members>
<signals>
+ <signal name="animation_changed">
+ <description>
+ Emitted when [member animation] changes.
+ </description>
+ </signal>
<signal name="animation_finished">
<description>
- Emitted when the animation reaches the end, or the start if it is played in reverse. If the animation is looping, this signal is emitted at the end of each loop.
+ Emitted when the animation reaches the end, or the start if it is played in reverse. When the animation finishes, it pauses the playback.
+ </description>
+ </signal>
+ <signal name="animation_looped">
+ <description>
+ Emitted when the animation loops.
</description>
</signal>
<signal name="frame_changed">
<description>
- Emitted when [member frame] changed.
+ Emitted when [member frame] changes.
+ </description>
+ </signal>
+ <signal name="sprite_frames_changed">
+ <description>
+ Emitted when [member sprite_frames] changes.
</description>
</signal>
</signals>