Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/doc/classes/AnimatedSprite2D.xml
10277 views
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/2712</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
Sets [member frame] and [member frame_progress] to the given values. Unlike setting [member frame], this method does not reset the [member frame_progress] to [code]0.0[/code] implicitly.
58
[b]Example:[/b] Change the animation while keeping the same [member frame] and [member frame_progress]:
59
[codeblocks]
60
[gdscript]
61
var current_frame = animated_sprite.get_frame()
62
var current_progress = animated_sprite.get_frame_progress()
63
animated_sprite.play("walk_another_skin")
64
animated_sprite.set_frame_and_progress(current_frame, current_progress)
65
[/gdscript]
66
[/codeblocks]
67
</description>
68
</method>
69
<method name="stop">
70
<return type="void" />
71
<description>
72
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].
73
</description>
74
</method>
75
</methods>
76
<members>
77
<member name="animation" type="StringName" setter="set_animation" getter="get_animation" default="&amp;&quot;default&quot;">
78
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.
79
</member>
80
<member name="autoplay" type="String" setter="set_autoplay" getter="get_autoplay" default="&quot;&quot;">
81
The key of the animation to play when the scene loads.
82
</member>
83
<member name="centered" type="bool" setter="set_centered" getter="is_centered" default="true">
84
If [code]true[/code], texture will be centered.
85
[b]Note:[/b] 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 [code]false[/code], or consider enabling [member ProjectSettings.rendering/2d/snap/snap_2d_vertices_to_pixel] and [member ProjectSettings.rendering/2d/snap/snap_2d_transforms_to_pixel].
86
</member>
87
<member name="flip_h" type="bool" setter="set_flip_h" getter="is_flipped_h" default="false">
88
If [code]true[/code], texture is flipped horizontally.
89
</member>
90
<member name="flip_v" type="bool" setter="set_flip_v" getter="is_flipped_v" default="false">
91
If [code]true[/code], texture is flipped vertically.
92
</member>
93
<member name="frame" type="int" setter="set_frame" getter="get_frame" default="0">
94
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].
95
</member>
96
<member name="frame_progress" type="float" setter="set_frame_progress" getter="get_frame_progress" default="0.0">
97
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].
98
</member>
99
<member name="offset" type="Vector2" setter="set_offset" getter="get_offset" default="Vector2(0, 0)">
100
The texture's drawing offset.
101
</member>
102
<member name="speed_scale" type="float" setter="set_speed_scale" getter="get_speed_scale" default="1.0">
103
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.
104
If set to a negative value, the animation is played in reverse. If set to [code]0[/code], the animation will not advance.
105
</member>
106
<member name="sprite_frames" type="SpriteFrames" setter="set_sprite_frames" getter="get_sprite_frames">
107
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.
108
</member>
109
</members>
110
<signals>
111
<signal name="animation_changed">
112
<description>
113
Emitted when [member animation] changes.
114
</description>
115
</signal>
116
<signal name="animation_finished">
117
<description>
118
Emitted when the animation reaches the end, or the start if it is played in reverse. When the animation finishes, it pauses the playback.
119
[b]Note:[/b] This signal is not emitted if an animation is looping.
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>
139
140