AnimatedSprite

Inherits: Node2D < CanvasItem < Node < Object

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

Description

AnimatedSprite is similar to the Sprite 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.

Note: You can associate a set of normal maps by creating additional animations with a _normal suffix. For example, having 2 animations run and run_normal will make it so the run animation uses the normal map.

Tutorials

Properties

String

animation

"default"

bool

centered

true

bool

flip_h

false

bool

flip_v

false

int

frame

0

SpriteFrames

frames

Vector2

offset

Vector2( 0, 0 )

bool

playing

false

float

speed_scale

1.0

Methods

void

play ( String anim="", bool backwards=false )

void

stop ( )


Signals

animation_finished ( )

Emitted when the animation is finished (when it plays the last frame). If the animation is looping, this signal is emitted every time the last frame is drawn.


frame_changed ( )

Emitted when frame changed.


Property Descriptions

String animation = "default"

  • void set_animation ( String value )

  • String get_animation ( )

The current animation from the frames resource. If this value changes, the frame counter is reset.


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.


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


Vector2 offset = Vector2( 0, 0 )

The texture's drawing offset.


bool playing = false

  • void set_playing ( bool value )

  • bool is_playing ( )

If true, the animation is currently playing.


float speed_scale = 1.0

  • void set_speed_scale ( float value )

  • float get_speed_scale ( )

The animation speed is multiplied by this value.


Method Descriptions

void play ( String anim="", bool backwards=false )

Plays the animation named anim. If no anim is provided, the current animation is played. If backwards is true, the animation will be played in reverse.


void stop ( )

Stops the current animation (does not reset the frame counter).