Work in progress
Godot documentation is being updated to reflect the latest changes in version
4.0. Some documentation pages may
still state outdated information. This banner will tell you if you're reading one of such pages.
The contents of this page are up to date. If you can still find outdated information, please open an issue.
Inherits: Node2D < CanvasItem < Node < Object
Sprite node that contains multiple textures as frames to play for animation.
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.
get_playing_speed ( ) const
is_playing ( ) const
pause ( )
play ( StringName name=&"", float custom_speed=1.0, bool from_end=false )
play_backwards ( StringName name=&"" )
set_frame_and_progress ( int frame, float progress )
stop ( )
animation_changed ( )
Emitted when animation changes.
animation_finished ( )
Emitted when the animation reaches the end, or the start if it is played in reverse. When the animation finishes, it pauses the playback.
animation_looped ( )
Emitted when the animation loops.
frame_changed ( )
Emitted when frame changes.
sprite_frames_changed ( )
Emitted when sprite_frames changes.
StringName animation =
void set_animation ( StringName value )
StringName get_animation ( )
The current animation from the sprite_frames resource. If this value is changed, the frame counter and the frame_progress are reset.
String autoplay =
The key of the animation to play when the scene loads.
bool centered =
true, texture will be centered.
bool flip_h =
true, texture is flipped horizontally.
bool flip_v =
true, texture is flipped vertically.
int frame =
The displayed animation frame's index. Setting this property also resets frame_progress. If this is not desired, use set_frame_and_progress.
float frame_progress =
The progress value between
1.0 until the current frame transitions to the next frame. If the animation is playing backwards, the value transitions from
Vector2 offset =
The texture's drawing offset.
float speed_scale =
The speed scaling ratio. For example, if this value is
1, then the animation plays at normal speed. If it's
0.5, then it plays at half speed. If it's
2, then it plays at double speed.
If set to a negative value, the animation is played in reverse. If set to
0, the animation will not advance.
void set_sprite_frames ( SpriteFrames value )
SpriteFrames 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.
float get_playing_speed ( ) const
Returns the actual playing speed of current animation or
0 if not playing. This speed is the speed_scale property multiplied by
custom_speed argument specified when calling the play method.
Returns a negative value if the current animation is playing backwards.
bool is_playing ( ) const
true if an animation is currently playing (even if speed_scale and/or
void pause ( )
Pauses the currently playing animation. The frame and frame_progress will be kept and calling play or play_backwards without arguments will resume the animation from the current playback position.
See also stop.
void play ( StringName name=&"", float custom_speed=1.0, bool from_end=false )
Plays the animation with key
custom_speed is negative and
true, the animation will play backwards (which is equivalent to calling play_backwards).
If this method is called with that same animation
name, or with no
name parameter, the assigned animation will resume playing if it was paused.
void play_backwards ( StringName name=&"" )
Plays the animation with key
name in reverse.
This method is a shorthand for play with
custom_speed = -1.0 and
from_end = true, so see its description for more information.
void set_frame_and_progress ( int frame, float progress )
The setter of frame resets the frame_progress to
0.0 implicitly, but this method avoids that.
This is useful when you want to carry over the current frame_progress to another frame.
# 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)
void stop ( )
Stops the currently playing animation. The animation position is reset to
0 and the
custom_speed is reset to
1.0. See also pause.