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.

SpriteFrames

繼承: Resource < RefCounted < Object

精靈影格庫,用於 AnimatedSprite2D 和 AnimatedSprite3D。

說明

AnimatedSprite2DAnimatedSprite3D 節點的精靈影格庫。包含影格和用於播放的動畫信息。

方法

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

clear_all()

void

duplicate_animation(anim_from: StringName, anim_to: StringName)

bool

get_animation_loop(anim: StringName) const

LoopMode

get_animation_loop_mode(anim: StringName) const

PackedStringArray

get_animation_names() const

float

get_animation_speed(anim: StringName) const

int

get_frame_count(anim: StringName) const

float

get_frame_duration(anim: StringName, idx: int) const

Texture2D

get_frame_texture(anim: StringName, idx: int) const

bool

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_loop_mode(anim: StringName, loop_mode: LoopMode)

void

set_animation_speed(anim: StringName, fps: float)

void

set_frame(anim: StringName, idx: int, texture: Texture2D, duration: float = 1.0)


列舉

enum LoopMode: 🔗

LoopMode LOOP_NONE = 0

The animation plays once and stops when it reaches the end, or the start if played in reverse.

LoopMode LOOP_LINEAR = 1

The animation restarts from the beginning when it reaches the end, or from the end if played in reverse, repeating continuously.

LoopMode LOOP_PINGPONG = 2

The animation alternates direction each time it reaches the end or start, playing forward and then in reverse repeatedly.

Note: Both AnimatedSprite2D and AnimatedSprite3D play the first/last frame for its duration only once at each end of the animation loop (instead of twice, once per forward/backward animation direction).


方法說明

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 🔗

已棄用: Use get_animation_loop_mode() instead.

Returns true if get_animation_loop_mode(anim) == LOOP_LINEAR. Otherwise, returns false.


LoopMode get_animation_loop_mode(anim: StringName) const 🔗

Returns the loop mode for the anim animation.


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_speedAnimatedSprite2D.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) 🔗

已棄用: Use set_animation_loop_mode() instead.

If loop is false equivalent to set_animation_loop_mode(LOOP_NONE).

If loop is true equivalent to set_animation_loop_mode(LOOP_LINEAR).


void set_animation_loop_mode(anim: StringName, loop_mode: LoopMode) 🔗

Sets the loop_mode for the anim animation.


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.