我为一位角色制作了一个眨眼动画,我希望这个角色每眨一次眼就等随机一段时间再眨一次,我想用信号的方式实现它
但我不知道func on骨架_animation_completed(spine_sprite: Object, animation_state: Object, track_entry: Object)的作用,有哪位大佬帮我解释一下谢谢~
如何让Spine动画播放完后出发信号?
在 spine-godot
中,你可以使用 SpineSprite
的信号来实现动画播放完后的处理。具体来说,animation_completed
信号会在动画在一个轨道上完成一个循环时发出。你可以连接这个信号到一个函数,以便在动画完成时执行特定的逻辑。
例如,你可以在 GDScript 中这样实现:
extends SpineSprite
func _ready():
var animation_state = get_animation_state()
animation_state.set_animation("blink", false, 0)
connect("animation_completed", self, "_on_animation_completed")
func _on_animation_completed(spine_sprite, animation_state, track_entry):
# 在这里实现你的逻辑,比如等待随机时间后再次播放动画
var random_delay = randi() % 3 + 1 # 随机等待1到3秒
yield(get_tree().create_timer(random_delay), "timeout")
animation_state.set_animation("blink", false, 0)
在这个例子中,当 blink
动画完成时,_on_animation_completed
函数会被调用。然后,它会等待一个随机的时间(1到3秒),再重新设置 blink
动画。
Spinebot 效果似乎不错,但我发现当我结合其他动画的时候其他动画播完而眨眼动画没播完的时候就开始重新播放眨眼动画了,这不是我所想要的,我希望能指定某个动画名称
Spinebot 而且上面代码的语法是Godot3版本的,我现在用的4.4.1版本,代码需要一些修改
Cyan_Bean Generally, to receive specific animation events at runtime, you would use the TrackEntry event. However, due to the limitations of GDScript, this is not currently possible. This is explained in the following section of the spine-godot runtime documentation:
spine-godot 运行时文档 #访问Spine运行时API
Instead, you can connect to the AnimationState's animation_complete
signal, check the name of the completed animation, and perform actions if it is "blink". The if-statement for this can be written as:
if track_entry.get_animation().get_name() == "blink":
# Your logic here
Misaki 成功了!感谢