Class reference
SpriteFrames
Inherits Resource
Sprite frame library for AnimatedSprite2D and AnimatedSprite3D.
Description
Sprite frame library for an AnimatedSprite2D or AnimatedSprite3D node. Contains frames and animation data for playback.
Methods
void add_animation(StringName anim)
StringName anim)Adds a new anim animation to the library.
void add_frame(StringName anim, Texture2D texture, float duration = 1.0, int at_position = -1)
StringName anim, Texture2D texture, float duration = 1.0, int at_position = -1)Adds a frame to the anim animation. If at_position is -1, the frame will be added to the end of the animation. duration specifies the relative duration, see get_frame_duration() for details.
void clear(StringName anim)
StringName anim)Removes all frames from the anim animation.
void clear_all()
Removes all animations. An empty default animation will be created.
SpriteFrames create_from_image_frames(ImageFrames image_frames) static
SpriteFrames create_from_image_frames(ImageFrames image_frames) staticCreates new a SpriteFrames object and initializes it by allocating and setting the "default" animation from an ImageFrames.
void duplicate_animation(StringName anim_from, StringName anim_to)
StringName anim_from, StringName anim_to)Duplicates the animation anim_from to a new animation named anim_to. Fails if anim_to already exists, or if anim_from does not exist.
bool get_animation_loop(StringName anim) const
bool get_animation_loop(StringName anim) constReturns true if the given animation is configured to loop when it finishes playing. Otherwise, returns false.
PackedStringArray get_animation_names() const
PackedStringArray get_animation_names() constReturns an array containing the names associated to each animation. Values are placed in alphabetical order.
float get_animation_speed(StringName anim) const
float get_animation_speed(StringName anim) constReturns the speed in frames per second for the anim animation.
int get_frame_count(StringName anim) const
int get_frame_count(StringName anim) constReturns the number of frames for the anim animation.
float get_frame_duration(StringName anim, int idx) const
float get_frame_duration(StringName anim, int idx) constReturns a relative duration of the frame idx in the anim animation (defaults to 1.0). For example, a frame with a duration of 2.0 is displayed twice as long as a frame with a duration of 1.0. You can calculate the absolute duration (in seconds) of a frame using the following formula:
absolute_duration = relative_duration / (animation_fps * abs(playing_speed))
In this example, playing_speed refers to either AnimatedSprite2D.get_playing_speed() or AnimatedSprite3D.get_playing_speed().
Texture2D get_frame_texture(StringName anim, int idx) const
Texture2D get_frame_texture(StringName anim, int idx) constReturns the texture of the frame idx in the anim animation.
bool has_animation(StringName anim) const
bool has_animation(StringName anim) constReturns true if the anim animation exists.
ImageFrames make_image_frames(StringName anim = &"default") const
ImageFrames make_image_frames(StringName anim = &"default") constCreates a new ImageFrames object from contents in the anim animation.
void remove_animation(StringName anim)
StringName anim)Removes the anim animation.
void remove_frame(StringName anim, int idx)
StringName anim, int idx)Removes the anim animation's frame idx.
void rename_animation(StringName anim, StringName newname)
StringName anim, StringName newname)Changes the anim animation's name to newname.
void set_animation_loop(StringName anim, bool loop)
StringName anim, bool loop)If loop is true, the anim animation will loop when it reaches the end, or the start if it is played in reverse.
void set_animation_speed(StringName anim, float fps)
StringName anim, float fps)Sets the speed for the anim animation in frames per second.
void set_frame(StringName anim, int idx, Texture2D texture, float duration = 1.0)
StringName anim, int idx, Texture2D texture, float duration = 1.0)Sets the texture and the duration of the frame idx in the anim animation. duration specifies the relative duration, see get_frame_duration() for details.
void set_from_image_frames(ImageFrames image_frames, StringName anim = &"default")
ImageFrames image_frames, StringName anim = &"default")Replaces the animations's data with a new ImageFrames for the anim animation.