The problem is that each frame you are changing the animation to either run or idle, and then you change it to jump. As you changed it previously, jump animation starts over every frame. Look at this:
After this piece of code, animation will be either “run” or “idle”, as it will always enter one of those three cases. After that you enter this case:
if not is_on_floor():
$AnimatedSprite.play("jump")
And “jump” starts from the beginning.
You could try something like this instead:
if Input.is_action_pressed("ui_right"):
velocity.x = SPEED
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
$AnimatedSprite.flip_h = true
if not is_on_floor():
$AnimatedSprite.play("jump")
elif abs(velocity.x) == SPEED:
$AnimatedSprite.play("run")
else:
$AnimatedSprite.play("idle")
I tried and succeeded. Thanks.
But I see someone do like me and have no problem
J.Delta | 2020-08-28 14:33
Hi! can you share that other code? if it is just like yours, it should have the same problem. He must be doing somemthing different. Because the logic of your code is as i explained, if im not mistaken or overseeing anything.
p7f | 2020-08-28 14:37
I watch that tutorial video again.
His jump animation just has 1 frame. If it has more, it will have problem.
Now, I’m understand.
Thank you so much!!!
(My English is too bad, hope you sympathize)
J.Delta | 2020-08-28 14:58
Glad to help! If this works to you, you may select the answer so others can see its solved.