When press a key start animation

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

Hello, i’ve just started learning to use Godot Engine an I love it, but i have a problem:

I want to play an animation when press a key, in this case the “Z” key but i just get the first frame of the animation played only and there are 4 frames on it, this is my code:

func _process(delta):
if Input.is_key_pressed(KEY_Z):
	$spr_player.animation = "Charge"

i’ve tried different ways but always get only the first frame of the animation:

get_node("spr_player").play("Charge")

and

$spr_player.play("Charge")

I dont understand why doesn’t work because this ones work without problem:

if move.x != 0:
	$spr_player.animation = "Run"
	$spr_player.flip_h = move.x < 0
elif move.y < 0:
	$spr_player.animation = "Jump"
elif move.y > 0:
	$spr_player.animation = "Down"
else:
	$spr_player.animation = "Standing"

Thnx a lot.

Where do you call get_node("spr_player").play("Charge")?

MaaaxiKing | 2020-06-04 10:49

:bust_in_silhouette: Reply From: Becbunzen

Did you marke the loop checkbox for the animation?

:bust_in_silhouette: Reply From: checharor

I’ve already fix It.

I didn’t know that the previous actions that I call affected the animation, I used the same code a few lines above and that did the trick, thnx a lot for your answers