0
\$\begingroup\$

I have tried checking if it is already playing, stopping animations before and putting it in a separate function. Whenever I jump it should play 4 Frames of my animated sprite. But it only plays first.

const FLOOR = Vector2(0,-1)
const SPEED = 500
const GRAVITY = 20
const JUMP = -600

func _physics_process(delta):
    pos.y += GRAVITY
    if Input.is_action_pressed("ui_right"):
        pos.x = SPEED
        $Sprite.play("Run")
        $Sprite.flip_h = false
    elif Input.is_action_pressed("ui_left"):
        pos.x = -SPEED
        $Sprite.play("Run")
        $Sprite.flip_h = true
    else:
        pos.x = 0
        $Sprite.play("Idle")
    if is_on_floor():
        if Input.is_action_just_pressed("ui_up"):
            pos.y = JUMP
    else:
        if pos.y < 0:
            $Sprite.play("Jump")
        else:
            $Sprite.play("Fall")
    pos = move_and_slide(pos,FLOOR)
```
\$\endgroup\$
0
\$\begingroup\$

You're telling your sprite to switch animations every frame while jumping, so it never gets past the first frame. Take a look at what code executes when is_on_floor() is true and pos.y < 0. You first try to play "Idle" (or "Run", if a direction key is pressed). Then you try to play "Jump", which starts at the first frame. On the next loop, you switch to "Idle" again, then back to "Jump" (resetting to the first frame).

Try to restructure your code so you are only calling play on one animation each loop.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.