Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

AnimatedSprite2D

Inherits: Node2D < CanvasItem < Node < Object

Sprite node that contains multiple textures as frames to play for animation.

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.

Tutorials

Properties

StringName

animation

&"default"

String

autoplay

""

bool

centered

true

bool

flip_h

false

bool

flip_v

false

int

frame

0

float

frame_progress

0.0

Vector2

offset

Vector2(0, 0)

float

speed_scale

1.0

SpriteFrames

sprite_frames

Methods

float

get_playing_speed ( ) const

bool

is_playing ( ) const

void

pause ( )

void

play ( StringName name=&"", float custom_speed=1.0, bool from_end=false )

void

play_backwards ( StringName name=&"" )

void

set_frame_and_progress ( int frame, float progress )

void

stop ( )


Signals

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.


Property Descriptions

StringName animation = &"default"

The current animation from the sprite_frames resource. If this value is changed, the frame counter and the frame_progress are reset.


String autoplay = ""

  • void set_autoplay ( String value )

  • String get_autoplay ( )

The key of the animation to play when the scene loads.


bool centered = true

  • void set_centered ( bool value )

  • bool is_centered ( )

If true, texture will be centered.


bool flip_h = false

  • void set_flip_h ( bool value )

  • bool is_flipped_h ( )

If true, texture is flipped horizontally.


bool flip_v = false

  • void set_flip_v ( bool value )

  • bool is_flipped_v ( )

If true, texture is flipped vertically.


int frame = 0

  • void set_frame ( int value )

  • int get_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 = 0.0

  • void set_frame_progress ( float value )

  • float get_frame_progress ( )

The progress value between 0.0 and 1.0 until the current frame transitions to the next frame. If the animation is playing backwards, the value transitions from 1.0 to 0.0.


Vector2 offset = Vector2(0, 0)

The texture's drawing offset.


float speed_scale = 1.0

  • void set_speed_scale ( float value )

  • float get_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.


SpriteFrames 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.


Method Descriptions

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

Returns true if an animation is currently playing (even if speed_scale and/or custom_speed are 0).


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 name<