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...
AnimatedTexture
已弃用: This class does not work properly in current versions and may be removed in the future. There is currently no equivalent workaround.
继承: Texture2D < Texture < Resource < RefCounted < Object
用于简单帧动画的代理纹理。
描述
AnimatedTexture 是一种用于帧动画的资源格式,其中多个纹理可以自动链接,每个帧都有预定义的延迟。与 AnimationPlayer 或 AnimatedSprite2D 不同,它不是 Node,但具有可在任何可以使用 Texture2D 资源的地方使用的优势,例如在 TileSet 中。
动画的播放由 speed_scale 属性以及每帧的持续时间(见 set_frame_duration())控制。动画是循环播放的,即它会在播放完最后一帧后自动从第 0 帧重新开始。
AnimatedTexture 目前要求所有帧的纹理具有相同的大小,否则较大的纹理将被裁剪以匹配最小的纹理。
注意:AnimatedTexture 不支持使用 AtlasTexture。 每个帧都需要是一个单独的 Texture2D。
警告:当前的实现对于现代渲染器来说效率不高。
属性
|
||
|
||
|
||
resource_local_to_scene |
|
|
|
方法
get_frame_duration(frame: int) const |
|
get_frame_texture(frame: int) const |
|
void |
set_frame_duration(frame: int, duration: float) |
void |
set_frame_texture(frame: int, texture: Texture2D) |
常量
MAX_FRAMES = 256
🔗
AnimatedTexture 支持的最大帧数。如果动画需要更多帧,请使用 AnimationPlayer 或 AnimatedSprite2D。
属性说明
设置纹理的当前可见帧。在播放时设置此帧会重置当前帧时间,因此新选择的帧将播放为其配置的整个帧持续时间。
动画中要使用的帧数。虽然你可以使用 set_frame_texture() 独立创建帧,但是你需要为动画设置这个值,才能考虑到新帧。最大帧数为 MAX_FRAMES。
如果为 true
,则动画将只播放一次,并且在到达结尾后将不会循环回到第一帧。请注意,到达终点不会将 pause 设置为 true
。
如果为 true
,则动画将暂停在当前位置(即 current_frame)。将此属性更改为 false
时,动画将从暂停处继续播放。
动画速度将乘以该值。如果设置为负值,则动画反向播放。
方法说明
float get_frame_duration(frame: int) const 🔗
返回给定的 frame
的持续时间,以秒为单位。
Texture2D get_frame_texture(frame: int) const 🔗
返回给定帧的 Texture2D。
void set_frame_duration(frame: int, duration: float) 🔗
设置任何给定 frame
的持续时间。最终的持续时间受 speed_scale 影响。如果设置为 0
,则该帧在播放过程中被跳过。
void set_frame_texture(frame: int, texture: Texture2D) 🔗
将 Texture2D 分配给给定的帧。帧 ID 从 0 开始,因此第一帧的 ID 为 0,动画的最后一帧的 ID 为 frames - 1。
最多可以定义 MAX_FRAMES 个纹理,但要记住,只有 0 到 frames - 1 的帧会成为动画的一部分。