SpriteFrames
继承: Resource < RefCounted < Object
Sprite frame library for AnimatedSprite2D and AnimatedSprite3D.
描述
Sprite frame library for an AnimatedSprite2D or AnimatedSprite3D node. Contains frames and animation data for playback.
方法
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 ) const1 |
PackedStringArray | get_animation_names ( ) const1 |
float | get_animation_speed ( anim: StringName ) const1 |
int | get_frame_count ( anim: StringName ) const1 |
float | get_frame_duration ( anim: StringName, idx: int ) const1 |
Texture2D | get_frame_texture ( anim: StringName, idx: int ) const1 |
bool | has_animation ( anim: StringName ) const1 |
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 )
Adds a new anim animation to the library.
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 )
Removes all frames from the anim animation.
void clear_all ( )
Removes all animations. An empty default animation will be created.
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 ) const1
Returns true if the given animation is configured to loop when it finishes playing. Otherwise, returns false.
PackedStringArray get_animation_names ( ) const1
Returns an array containing the names associated to each animation. Values are placed in alphabetical order.
float get_animation_speed ( anim: StringName ) const1
Returns the speed in frames per second for the anim animation.
int get_frame_count ( anim: StringName ) const1
Returns the number of frames for the anim animation.
float get_frame_duration ( anim: StringName, idx: int ) const1
Returns a relative duration of the frame idx in the anim animation (defaults to 1.0). For example, a frame with a duration of 2.0 is displayed twice as long as a frame with a duration of 1.0. You can calculate the absolute duration (in seconds) of a frame using the following formula:
absolute_duration = relative_duration / (animation_fps * abs(playing_speed))
In this example, playing_speed refers to either AnimatedSprite2D.get_playing_speed or AnimatedSprite3D.get_playing_speed.
Texture2D get_frame_texture ( anim: StringName, idx: int ) const1
Returns the texture of the frame idx in the anim animation.
bool has_animation ( anim: StringName ) const1
Returns true if the anim animation exists.
void remove_animation ( anim: StringName )
Removes the anim animation.
void remove_frame ( anim: StringName, idx: int )
Removes the anim animation's frame idx.
void rename_animation ( anim: StringName, newname: StringName )
Changes the anim animation's name to newname.
void set_animation_loop ( anim: StringName, loop: bool )
If loop is true, the anim animation will loop when it reaches the end, or the start if it is played in reverse.
void set_animation_speed ( anim: StringName, fps: float )
Sets the speed for the anim animation in frames per second.
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.
本方法通常需要用户覆盖才能生效。
本方法无副作用,不会修改该实例的任何成员变量。
本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。
本方法用于构造某个类型。
调用本方法无需实例,可直接使用类名进行调用。
本方法描述的是使用本类型作为左操作数的有效运算符。
这个值是由下列位标志构成位掩码的整数。
无返回值。