I am learning Godot 3.0 and I have a question concerning animation.
I have a player object whose node structure is KinematicBody2D > Sprite > AnimationPlayer. In the AnimationPlayer, I have ascend and descend animations that I want to play until their final frames, at which point I want to hold on those frames.
For now, I initiate my animations using the following function, which looks at my player's state
attribute:
func animate():
var animation_player = $Sprite.get_node("AnimationPlayer")
# image matches orientation
if orientation == "LEFT":
$Sprite.flip_h = true
else:
$Sprite.flip_h = false
# animation depends on state
if state == "idle":
if not ["idle"].has(animation_player.current_animation):
animation_player.play("idle")
if state == "run":
if not ["run"].has(animation_player.current_animation):
animation_player.play("run")
if state == "ascend":
if not ["ascend"].has(animation_player.current_animation):
animation_player.play("ascend")
if state == "descend":
if not ["descend"].has(animation_player.current_animation):
animation_player.play("descend")
I have disabled looping for my ascend and descend animations and yet they still loop. Probably because when their animation finishes, the idle animation starts and is then immediately changed back to ascend or descend since the player is still in this state.
So my question is: How do I go about holding on the final frame of certain animations?
I have looked into the animation_finished()
signal of the AnimationPlayer, but I can't figure out how to use it properly.
All I can think to do is use a Call Func track on the ascend and descend animations, calling a custom function at the end of these animations which switches to a different, single-frame but looped animation (ascend_static or descend_static). But surely there is a better way?
animate
and change thestate
? \$\endgroup\$