0 votes

Hi, im new in the Godot and programming.

I have an animation which has 9 frames, I want it to start in frame 0, but when it reaches frame 3, it will be repeated in a loop from 3 to 9.

Im used AnimatedSprite, because I have each animation separately

I have tried too many formulas and nothing works for me, here my scrip:

if int(Input.isactionjustpressed("uidown")):
$AnimatedSprite.play("Sentandose")
if $AnimatedSprite.frame ==3:
$AnimatedSprite.frames_loop(4,9)

in Engine by (28 points)

1 Answer

+2 votes
Best answer

I would take your animation and make a second one of just the part you want looped (3-9), which is easy in the Animation player.
In the Animation Player, select the animation keys you want to duplicate (all of them in 3-9) so they are selected. Then click the Edit button, and choose Duplicate Selection.
Now you have your original animation, and your new one, a copy that only contains frames 3-9 (as frames 0-6). Set that new animation to loop with the Animation Looping button.
Now dump frames 3-9 out of your original so it only contains the non-repeating frames.

Then something like this:

 func _process(delta):
    if Input.is_action_just_pressed("ui_down"):
        play_my_animation()

 func _play_my_animation():
    $AnimatiedSprite.play("original_non_repeating_animation")
    yield ($AnimatedSprite, "animation_finished")
    $Animated_Sprite.play("new_repeating_frames_animation")
by (337 points)
selected by

thank you. It works perfectly, but I didn't have to create the functions since it works in "isonfloor ()"

thats is the result:

if Input.is_action_just_pressed("ui_down"):
        $AnimatedSprite.play("Sentandose")
        yield ($AnimatedSprite, "animation_finished")
        $AnimatedSprite.play("Sentado")
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 Frequently asked questions and 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 [email protected] with your username.