How can I make the code identify if an animation is playing?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By WorkedPython

so to have multiple animation, I needed multiple sprites, but for this to work I need only one sprite shown at one time and the rest hidden. This is my attempt (obviously not working). How can I make it so that the code detects if a particular animation is playing and then accordingly hide a show sprites.

func _process(_delta):
	if Input.is_action_just_pressed("LMB"):
		_animation_player.play("jab")
	elif Input.is_action_just_pressed("RMB"):
		_animation_player.play("cross")
		
func punch_process(_delta):
	if _animation_player.play == false:
		get_node("PlayerJab").set_hidden
		get_node("PlayerCross").set_hidden
	elif _animation_player.play("jab") == true:
		get_node("PlayerJab").set_visible
	elif _animation_player.play("cross") == true:
		get_node("PlayerCross").set_visible
:bust_in_silhouette: Reply From: Gluon

There is a signal on animation players called finished. You can start a function when that signal is sent with something like this

animation.connect("finished", self, "FunctionWhenAnimationIsDone")

which will start a function once the animation has finished.

Thanks man but I figured out another way of animating which is easier.

WorkedPython | 2021-12-05 14:05