AnimatedTexture

Inherits: Texture < Resource < Reference < Object

Category: Core

Brief Description

Proxy texture for simple frame-based animations.

Properties

float fps
int frames

Methods

float get_frame_delay ( int frame ) const
Texture get_frame_texture ( int frame ) const
void set_frame_delay ( int frame, float delay )
void set_frame_texture ( int frame, Texture texture )

Constants

  • MAX_FRAMES = 256 --- The maximum number of frames supported by AnimatedTexture. If you need more frames in your animation, use AnimationPlayer or AnimatedSprite.

Description

AnimatedTexture is a resource format for simple frame-based animations, where multiple frames textures can be chained automatically with a predefined delay for each frame. It's not a Node, contrarily to AnimationPlayer or AnimatedSprite, but has the advantage of being usable at any place where a Texture resource can be used, e.g. in a TileSet.

The playback of the animation is controlled by the fps property as well as each frame's optional delay (see set_frame_delay). 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.

Property Descriptions

Setter set_fps(value)
Getter get_fps()

Number of frames per second. This value defines the default time interval between two frames of the animation, and thus the overall duration of the animation loop based on the frames property. A value of 0 means no predefined number of frames per second, the animation will play according to each frame's frame delay (see set_frame_delay). Default value: 4.

For example, an animation with 8 frames, no frame delay and a fps value of 2 will run over 4 seconds, with one frame each 0.5 seconds.

Setter set_frames(value)
Getter get_frames()

Number of frames to use in the animation. While you can create the frames independently with 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. Default value: 1.

Method Descriptions

  • float get_frame_delay ( int frame ) const

Retrieves the delayed assigned to the given frame ID.

Retrieves the Texture assigned to the given frame ID.

  • void set_frame_delay ( int frame, float delay )

Defines an additional delay (in seconds) between this frame and the next one, that will be added to the time interval defined by fps. By default, frames have no delay defined. If a delay value is defined, the final time interval between this frame and the next will be 1.0 / fps + delay.

For example, for an animation with 3 frames, 2 FPS and a frame delay on the second frame of 1.2, the resulting playback will be:

Frame 0: 0.5 s (1 / fps)
Frame 1: 1.7 s (1 / fps + 1.2)
Frame 2: 0.5 s (1 / fps)
Total duration: 2.7 s
  • void set_frame_texture ( int frame, Texture texture )

Assigns a Texture to the given frame ID. 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 frame texture up to MAX_FRAMES, but keep in mind that only frames from 0 to frames - 1 will be part of the animation.