Not showing jump and fall animated sprites

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

Hi! I’m new in godot and in programming and i don’t know why the sprites don’t appear any advice will be great.
Thank you for you answer!

Here’s the code:

const SPEED = 350
const GRAVITY = 40
const JUMP = -1100
const FLOOR = Vector2(0, -1)

var velocity = Vector2()
var jumping = false
var falling = false

func _physics_process(delta: float) → void:

if Input.is_action_pressed("ui_right"):
	velocity.x = SPEED
	$AnimatedSprite.play("run")
	$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
	velocity.x = -SPEED
	$AnimatedSprite.play("run")
	$AnimatedSprite.flip_h = true
else:
	velocity.x = 0
	$AnimatedSprite.play("idle")

if is_on_floor():
	if not jumping and not falling:
		if Input.is_action_pressed("ui_up"):
			velocity.y = JUMP
			jumping = true
			if jumping:
				$AnimatedSprite.play("jump")
				jumping = false
				falling = true
				if falling:
					$AnimatedSprite.play("jump")
					falling = false

velocity.y += GRAVITY

velocity = move_and_slide(velocity, FLOOR)
:bust_in_silhouette: Reply From: p7f

As far as i can see, every frame you set either one of this animations: run or idle
After that, you may change that animation to fall or jump, but as you change it every frame (because previously you set run or idle) animation is restarted everey frame when you jump or fall.

Try something like this instead (although you will probably need to think about if that implementation is right for your use case):

if is_on_floor():
    if not jumping and not falling:
        if Input.is_action_pressed("ui_up"):
            velocity.y = JUMP
            jumping = true
            if jumping:
                $AnimatedSprite.play("jump")
                jumping = false
                falling = true
                if falling:
                    $AnimatedSprite.play("jump")
                    falling = false
elif Input.is_action_pressed("ui_right"):
    velocity.x = SPEED
    $AnimatedSprite.play("run")
    $AnimatedSprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
    velocity.x = -SPEED
    $AnimatedSprite.play("run")
    $AnimatedSprite.flip_h = true
else:
    velocity.x = 0
    $AnimatedSprite.play("idle")

velocity.y += GRAVITY

velocity = move_and_slide(velocity, FLOOR)