Class SpriteFrames
Sprite frame library for AnimatedSprite2D and AnimatedSprite3D.
- Inheritance
-
SpriteFrames
Remarks
Sprite frame library for an AnimatedSprite2D or AnimatedSprite3D node. Contains frames and animation data for playback.
Methods
add_animation(StringName)
Adds a new anim
animation to the library.
void add_animation(StringName anim)
Parameters
anim
StringName
add_frame(StringName, Texture2D, float, int)
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 SpriteFrames.get_frame_duration for details.
void add_frame(StringName anim, Texture2D texture, float duration, int at_position)
Parameters
anim
StringNametexture
Texture2Dduration
floatat_position
int
clear(StringName)
Removes all frames from the anim
animation.
void clear(StringName anim)
Parameters
anim
StringName
clear_all
Removes all animations. An empty default
animation will be created.
void clear_all
duplicate_animation(StringName, StringName)
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.
void duplicate_animation(StringName anim_from, StringName anim_to)
Parameters
anim_from
StringNameanim_to
StringName
get_animation_loop(StringName)
Qualifiers: const
Returns true
if the given animation is configured to loop when it finishes playing. Otherwise, returns false
.
bool get_animation_loop(StringName anim)
Parameters
anim
StringName
get_animation_names
Qualifiers: const
Returns an array containing the names associated to each animation. Values are placed in alphabetical order.
PackedStringArray get_animation_names
get_animation_speed(StringName)
Qualifiers: const
Returns the speed in frames per second for the anim
animation.
float get_animation_speed(StringName anim)
Parameters
anim
StringName
get_frame_count(StringName)
Qualifiers: const
Returns the number of frames for the anim
animation.
int get_frame_count(StringName anim)
Parameters
anim
StringName
get_frame_duration(StringName, int)
Qualifiers: const
Returns 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 get_playing_speed or get_playing_speed.
float get_frame_duration(StringName anim, int idx)
Parameters
anim
StringNameidx
int
get_frame_texture(StringName, int)
Qualifiers: const
Returns the texture of the frame idx
in the anim
animation.
Texture2D get_frame_texture(StringName anim, int idx)
Parameters
anim
StringNameidx
int
has_animation(StringName)
Qualifiers: const
Returns true
if the anim
animation exists.
bool has_animation(StringName anim)
Parameters
anim
StringName
remove_animation(StringName)
Removes the anim
animation.
void remove_animation(StringName anim)
Parameters
anim
StringName
remove_frame(StringName, int)
Removes the anim
animation's frame idx
.
void remove_frame(StringName anim, int idx)
Parameters
anim
StringNameidx
int
rename_animation(StringName, StringName)
Changes the anim
animation's name to newname
.
void rename_animation(StringName anim, StringName newname)
Parameters
anim
StringNamenewname
StringName
set_animation_loop(StringName, bool)
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_loop(StringName anim, bool loop)
Parameters
anim
StringNameloop
bool
set_animation_speed(StringName, float)
Sets the speed for the anim
animation in frames per second.
void set_animation_speed(StringName anim, float fps)
Parameters
anim
StringNamefps
float
set_frame(StringName, int, Texture2D, float)
Sets the texture
and the duration
of the frame idx
in the anim
animation. duration
specifies the relative duration, see SpriteFrames.get_frame_duration for details.
void set_frame(StringName anim, int idx, Texture2D texture, float duration)
Parameters
anim
StringNameidx
inttexture
Texture2Dduration
float