0 votes

I want to create an animation that puts the character in a certain position and then starts the loop, like from frame 0 to 4, then the loop goes from 5 until 9, without restarting from 0. I already tried creating two animations and creating another function with yield like the one below:

func _play_animation():

$Animation_swalking.play("start_walking")
yield ($Animation_swalking, "animation_finished")
$Animation_walking.play("walking")

func _physics_process(delta):
    if Input.is_action_pressed("right"):
        velocity.x = SPEED
        $Sprite.flip_h = false
        $Sprite.play("walking")
in Engine by (14 points)

Where is _play_animation() called?

I forgot to call it in the exemple, but it is supposed to be called when you press a key, like "left" or "right".

So $Animation_swalking and $Animation_walking are two different nodes?

Yes, they are

Why not use signals, rather than yields?
Maybe I don't use yield as much as I should.

If they're two different nodes, then are they visible at the same time? You don't hide either of them. Also, you should probably just use a signal instead of yield.

Could you give me an example in gdscript?

Not really. Are Sprite, Animation_swalking and Animation_walking all animatedsprites? Because sprites don't have play methods and you can have more than one animation for an animatedsprite.

func _on_animation_animation_finished(anim): 
  if anim.name == "start_running":
    $Animation.play("running")

Also, I don't really know if having two animation nodes will cause unexpected behavior, never really done it myself.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.