SpriteFrames
Inherits:Resource<RefCounted<Object
Sprite frame library for AnimatedSprite2D and AnimatedSprite3D.
Description
Sprite frame library for anAnimatedSprite2D orAnimatedSprite3D node. Contains frames and animation data for playback.
Methods
add_animation(anim:StringName) | |
add_frame(anim:StringName, texture:Texture2D, duration:float = 1.0, at_position:int = -1) | |
clear(anim:StringName) | |
duplicate_animation(anim_from:StringName, anim_to:StringName) | |
get_frame_duration(anim:StringName, idx:int)const | |
get_frame_texture(anim:StringName, idx:int)const | |
has_animation(anim:StringName)const | |
remove_animation(anim:StringName) | |
remove_frame(anim:StringName, idx:int) | |
rename_animation(anim:StringName, newname:StringName) | |
set_animation_loop(anim:StringName, loop:bool) | |
set_animation_speed(anim:StringName, fps:float) | |
set_frame(anim:StringName, idx:int, texture:Texture2D, duration:float = 1.0) |
Method Descriptions
voidadd_animation(anim:StringName)🔗
Adds a newanim animation to the library.
voidadd_frame(anim:StringName, texture:Texture2D, duration:float = 1.0, at_position:int = -1)🔗
Adds a frame to theanim animation. Ifat_position is-1, the frame will be added to the end of the animation.duration specifies the relative duration, seeget_frame_duration() for details.
Removes all frames from theanim animation.
Removes all animations. An emptydefault animation will be created.
voidduplicate_animation(anim_from:StringName, anim_to:StringName)🔗
Duplicates the animationanim_from to a new animation namedanim_to. Fails ifanim_to already exists, or ifanim_from does not exist.
boolget_animation_loop(anim:StringName)const🔗
Returnstrue if the given animation is configured to loop when it finishes playing. Otherwise, returnsfalse.
PackedStringArrayget_animation_names()const🔗
Returns an array containing the names associated to each animation. Values are placed in alphabetical order.
floatget_animation_speed(anim:StringName)const🔗
Returns the speed in frames per second for theanim animation.
intget_frame_count(anim:StringName)const🔗
Returns the number of frames for theanim animation.
floatget_frame_duration(anim:StringName, idx:int)const🔗
Returns a relative duration of the frameidx in theanim animation (defaults to1.0). For example, a frame with a duration of2.0 is displayed twice as long as a frame with a duration of1.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 eitherAnimatedSprite2D.get_playing_speed() orAnimatedSprite3D.get_playing_speed().
Texture2Dget_frame_texture(anim:StringName, idx:int)const🔗
Returns the texture of the frameidx in theanim animation.
boolhas_animation(anim:StringName)const🔗
Returnstrue if theanim animation exists.
voidremove_animation(anim:StringName)🔗
Removes theanim animation.
voidremove_frame(anim:StringName, idx:int)🔗
Removes theanim animation's frameidx.
voidrename_animation(anim:StringName, newname:StringName)🔗
Changes theanim animation's name tonewname.
voidset_animation_loop(anim:StringName, loop:bool)🔗
Ifloop istrue, theanim animation will loop when it reaches the end, or the start if it is played in reverse.
voidset_animation_speed(anim:StringName, fps:float)🔗
Sets the speed for theanim animation in frames per second.
voidset_frame(anim:StringName, idx:int, texture:Texture2D, duration:float = 1.0)🔗
Sets thetexture and theduration of the frameidx in theanim animation.duration specifies the relative duration, seeget_frame_duration() for details.