AnimatedSprite only plays first frame

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

I am following tutorials and I want to add attack feature myself. So I was working on the animation but it plays only first frame of animation. Other animation work fine but only attack animation do not work properly. I do not understand what is wrong. How do I play my whole animation.

here is my code for reference:

if input.x == 0:
	apply_friction()
	$AnimatedSprite.play("idle")
else:
	apply_acceleration(input.x)
	$AnimatedSprite.play("run")
	if input.x > 0:
		$AnimatedSprite.flip_h = false
	elif input.x < 0:
		$AnimatedSprite.flip_h = true


#jump
if is_on_floor():
	if Input.is_action_pressed("jump"):
		$AnimatedSprite.play("jump")
		velocity.y = jump_force
else:
	$AnimatedSprite.play("jump")
	if Input.is_action_just_released("jump") and velocity.y < -70:
		velocity.y = jump_release_force
	
	if velocity.y > 0:
		velocity.y += additional_fall_gravity
if Input.is_action_just_pressed("attack"):
	$AnimatedSprite.play("attack1") #<--- :(

velocity = move_and_slide(velocity, Vector2.UP)

What plays after the single attack animation frame? Looking at the code, there are lots of animations that could play in the very next frame depending on various conditions. For example, if you’re not moving in x, the idle animation will start in the next frame (and cancel the attack animation).

jgodfrey | 2022-12-14 03:53

:bust_in_silhouette: Reply From: DarthPlayer

Here is a 10 minute video on how to do attack animation, it helped me and i hope it can help you.