Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

SpriteFrames

继承: Resource < RefCounted < Object

精灵帧库,用于 AnimatedSprite2D 和 AnimatedSprite3D。

描述

AnimatedSprite2DAnimatedSprite3D 节点的精灵帧库。包含帧和用于播放的动画信息。

方法

void

add_animation ( StringName anim )

void

add_frame ( StringName anim, Texture2D texture, float duration=1.0, int at_position=-1 )

void

clear ( StringName anim )

void

clear_all ( )

bool

get_animation_loop ( StringName anim ) const

PackedStringArray

get_animation_names ( ) const

float

get_animation_speed ( StringName anim ) const

int

get_frame_count ( StringName anim ) const

float

get_frame_duration ( StringName anim, int idx ) const

Texture2D

get_frame_texture ( StringName anim, int idx ) const

bool

has_animation ( StringName anim ) const

void

remove_animation ( StringName anim )

void

remove_frame ( StringName anim, int idx )

void

rename_animation ( StringName anim, StringName newname )

void

set_animation_loop ( StringName anim, bool loop )

void

set_animation_speed ( StringName anim, float fps )

void

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


方法说明

void add_animation ( StringName anim )

向库中添加新动画 anim


void add_frame ( StringName anim, Texture2D texture, float duration=1.0, int at_position=-1 )

anim 动画中添加一帧。如果 at_position-1,则该帧会添加至该动画的末尾。


void clear ( StringName anim )

删除 anim 动画中的所有帧。


void clear_all ( )

移除所有动画。将创建名为 default 的空动画。


bool get_animation_loop ( StringName anim ) const

当指定的动画被配置为结束播放后循环时,返回 true,否则返回 false


PackedStringArray get_animation_names ( ) const

返回一个包含每个动画的名称的数组。值按字母顺序排列。


float get_animation_speed ( StringName anim ) const

返回 anim 动画的速度,单位为帧每秒。


int get_frame_count ( StringName anim ) const

返回 anim 动画中的帧数。


float get_frame_duration ( StringName anim, int idx ) const

返回 anim 动画中 idx 帧的相对持续时间(默认为 1.0)。例如,持续时间为 2.0 的帧的显示长度是持续时间为 1.0 的帧的两倍。可以使用如下公式计算某一帧的绝对持续时间(单位为秒):

absolute_duration = relative_duration / (animation_fps * abs(playing_speed))

在这个例子中,playing_speedAnimatedSprite2D.get_playing_speedAnimatedSprite3D.get_playing_speed


Texture2D get_frame_texture ( StringName anim, int idx ) const

返回 anim 动画中帧索引为 idx 的纹理。


bool has_animation ( StringName anim ) const

如果 anim 动画存在,则返回 true


void remove_animation ( StringName anim )

移除 anim 动画。


void remove_frame ( StringName anim, int idx )

移除 anim 动画中索引为 idx 的帧。


void rename_animation ( StringName anim, StringName newname )

anim 动画的名称更改为 newname


void set_animation_loop ( StringName anim, bool loop )

如果 looptrue,则 anim 动画会在到达结尾时循环,逆序播放时则为到达开头时循环。


void set_animation_speed ( StringName anim, float fps )

设置 anim 动画的速度,单位为帧每秒。


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

设置 anim 动画中索引为 idx 的帧的纹理 texture 和持续时间 duration