Table of Contents

Class AnimatedTexture

Proxy texture for simple frame-based animations.

Inheritance
AnimatedTexture

Remarks

AnimatedTexture is a resource format for frame-based animations, where multiple textures can be chained automatically with a predefined delay for each frame. Unlike AnimationPlayer or AnimatedSprite2D, it isn't a Node, but has the advantage of being usable anywhere a Texture2D resource can be used, e.g. in a TileSet.

The playback of the animation is controlled by the speed_scale property, as well as each frame's duration (see AnimatedTexture.set_frame_duration). The animation loops, i.e. it will restart at frame 0 automatically after playing the last frame.

AnimatedTexture currently requires all frame textures to have the same size, otherwise the bigger ones will be cropped to match the smallest one.

Note: AnimatedTexture doesn't support using AtlasTextures. Each frame needs to be a separate Texture2D.

Warning: The current implementation is not efficient for the modern renderers.

Fields

MAX_FRAMES

The maximum number of frames supported by AnimatedTexture. If you need more frames in your animation, use AnimationPlayer or AnimatedSprite2D.

const MAX_FRAMES = 256

Properties

current_frame

Sets the currently visible frame of the texture. Setting this frame while playing resets the current frame time, so the newly selected frame plays for its whole configured frame duration.

var current_frame : int

Property Value

int

Remarks

  • void set_current_frame(int value)
  • int get_current_frame

frames

Number of frames to use in the animation. While you can create the frames independently with AnimatedTexture.set_frame_texture, you need to set this value for the animation to take new frames into account. The maximum number of frames is MAX_FRAMES.

var frames : int = 1

Property Value

int

Remarks

  • void set_frames(int value)
  • int get_frames

one_shot

If true, the animation will only play once and will not loop back to the first frame after reaching the end. Note that reaching the end will not set pause to true.

var one_shot : bool = false

Property Value

bool

Remarks

  • void set_one_shot(bool value)
  • bool get_one_shot

pause

If true, the animation will pause where it currently is (i.e. at current_frame). The animation will continue from where it was paused when changing this property to false.

var pause : bool = false

Property Value

bool

Remarks

  • void set_pause(bool value)
  • bool get_pause

speed_scale

The animation speed is multiplied by this value. If set to a negative value, the animation is played in reverse.

var speed_scale : float = 1.0

Property Value

float

Remarks

  • void set_speed_scale(float value)
  • float get_speed_scale

Methods

get_frame_duration(int)

Qualifiers: const

Returns the given frame's duration, in seconds.

float get_frame_duration(int frame)

Parameters

frame int

get_frame_texture(int)

Qualifiers: const

Returns the given frame's Texture2D.

Texture2D get_frame_texture(int frame)

Parameters

frame int

set_frame_duration(int, float)

Sets the duration of any given frame. The final duration is affected by the speed_scale. If set to 0, the frame is skipped during playback.

void set_frame_duration(int frame, float duration)

Parameters

frame int
duration float

set_frame_texture(int, Texture2D)

Assigns a Texture2D to the given frame. Frame IDs start at 0, so the first frame has ID 0, and the last frame of the animation has ID frames - 1.

You can define any number of textures up to MAX_FRAMES, but keep in mind that only frames from 0 to frames - 1 will be part of the animation.

void set_frame_texture(int frame, Texture2D texture)

Parameters

frame int
texture Texture2D