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) 🔗
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(anim: StringName) 🔗
刪除 anim 動畫中的所有影格。
void clear_all() 🔗
移除所有動畫。將建立名為 default 的空動畫。
void duplicate_animation(anim_from: StringName, anim_to: 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.
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) 🔗
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.