Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
SpriteFrames
继承: Resource < RefCounted < Object
精灵帧库,用于 AnimatedSprite2D 和 AnimatedSprite3D。
描述
AnimatedSprite2D 和 AnimatedSprite3D 节点的精灵帧库。包含帧和用于播放的动画信息。
方法
void |
add_animation(anim: StringName) |
void |
add_frame(anim: StringName, texture: Texture2D, duration: float = 1.0, at_position: int = -1) |
void |
clear(anim: StringName) |
void |
|
void |
duplicate_animation(anim_from: StringName, anim_to: StringName) |
get_animation_loop(anim: StringName) const |
|
get_animation_names() const |
|
get_animation_speed(anim: StringName) const |
|
get_frame_count(anim: StringName) const |
|
get_frame_duration(anim: StringName, idx: int) const |
|
get_frame_texture(anim: StringName, idx: int) const |
|
has_animation(anim: StringName) const |
|
void |
remove_animation(anim: StringName) |
void |
remove_frame(anim: StringName, idx: int) |
void |
rename_animation(anim: StringName, newname: StringName) |
void |
set_animation_loop(anim: StringName, loop: bool) |
void |
set_animation_speed(anim: StringName, fps: float) |
void |
set_frame(anim: StringName, idx: int, texture: Texture2D, duration: float = 1.0) |
方法说明
void add_animation(anim: StringName) 🔗
向库中添加新动画 anim
。
void add_frame(anim: StringName, texture: Texture2D, duration: float = 1.0, at_position: int = -1) 🔗
向 anim
动画中添加一帧。如果 at_position
为 -1
,则该帧会添加至该动画的末尾。duration
指定的是相对时长,详见 get_frame_duration()。
void clear(anim: StringName) 🔗
删除 anim
动画中的所有帧。
void clear_all() 🔗
移除所有动画。将创建名为 default
的空动画。
void duplicate_animation(anim_from: StringName, anim_to: StringName) 🔗
将动画 anim_from
复制为名叫 anim_to
的新动画。如果 anim_to
已存在或 anim_from
不存在则会失败。
bool get_animation_loop(anim: StringName) const 🔗
当指定的动画被配置为结束播放后循环时,返回 true
,否则返回 false
。
PackedStringArray get_animation_names() const 🔗
返回一个包含每个动画的名称的数组。值按字母顺序排列。
float get_animation_speed(anim: StringName) const 🔗
返回 anim
动画的速度,单位为帧每秒。
int get_frame_count(anim: StringName) const 🔗
返回 anim
动画中的帧数。
float get_frame_duration(anim: StringName, idx: int) const 🔗
返回 anim
动画中 idx
帧的相对持续时间(默认为 1.0
)。例如,持续时间为 2.0
的帧的显示长度是持续时间为 1.0
的帧的两倍。可以使用如下公式计算某一帧的绝对持续时间(单位为秒):
absolute_duration = relative_duration / (animation_fps * abs(playing_speed))
在这个例子中,playing_speed
是 AnimatedSprite2D.get_playing_speed() 或 AnimatedSprite3D.get_playing_speed()。
Texture2D get_frame_texture(anim: StringName, idx: int) const 🔗
返回 anim
动画中帧索引为 idx
的纹理。
bool has_animation(anim: StringName) const 🔗
如果 anim
动画存在,则返回 true
。
void remove_animation(anim: StringName) 🔗
移除 anim
动画。
void remove_frame(anim: StringName, idx: int) 🔗
移除 anim
动画中索引为 idx
的帧。
void rename_animation(anim: StringName, newname: StringName) 🔗
将 anim
动画的名称更改为 newname
。
void set_animation_loop(anim: StringName, loop: bool) 🔗
如果 loop
为 true
,则 anim
动画会在到达结尾时循环,逆序播放时则为到达开头时循环。
void set_animation_speed(anim: StringName, fps: float) 🔗
设置 anim
动画的速度,单位为帧每秒。
void set_frame(anim: StringName, idx: int, texture: Texture2D, duration: float = 1.0) 🔗
设置 anim
动画中索引为 idx
的帧的纹理 texture
和持续时间 duration
。duration
指定的是相对时长,详见 get_frame_duration()。