godot.AnimatedTexture
is a resource format for frame-based animations, where multiple textures can be chained automatically with a predefined delay for each frame. Unlike godot.AnimationPlayer
or godot.AnimatedSprite
, it isn't a godot.Node
, but has the advantage of being usable anywhere a godot.Texture
resource can be used, e.g. in a godot.TileSet
.
The playback of the animation is controlled by the godot.AnimatedTexture.fps
property as well as each frame's optional delay (see godot.AnimatedTexture.setFrameDelay
). The animation loops, i.e. it will restart at frame 0 automatically after playing the last frame.
godot.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 godot.AtlasTexture
s. Each frame needs to be a separate godot.Texture
.
Static variables
staticread onlyMAX_FRAMES:Int
The maximum number of frames supported by godot.AnimatedTexture
. If you need more frames in your animation, use godot.AnimationPlayer
or godot.AnimatedSprite
.
Constructor
Variables
fps:Single
Animation speed in 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 godot.AnimatedTexture.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 godot.AnimatedTexture.setFrameDelay
).
For example, an animation with 8 frames, no frame delay and a fps
value of 2 will run for 4 seconds, with each frame lasting 0.5 seconds.
frames:Int
Number of frames to use in the animation. While you can create the frames independently with godot.AnimatedTexture.setFrameTexture
, you need to set this value for the animation to take new frames into account. The maximum number of frames is godot.AnimatedTexture.maxFrames
.
oneshot:Bool
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 godot.AnimatedTexture.pause
to true
.
pause:Bool
If true
, the animation will pause where it currently is (i.e. at godot.AnimatedTexture.currentFrame
). The animation will continue from where it was paused when changing this property to false
.
Methods
setFrameDelay(frame:Int, delay:Single):Void
Sets an additional delay (in seconds) between this frame and the next one, that will be added to the time interval defined by godot.AnimatedTexture.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
setFrameTexture(frame:Int, texture:Texture):Void
Assigns a godot.Texture
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 godot.AnimatedTexture.frames
- 1.
You can define any number of textures up to godot.AnimatedTexture.maxFrames
, but keep in mind that only frames from 0 to godot.AnimatedTexture.frames
- 1 will be part of the animation.