How can I loop an animation that is not from 0 frames?

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

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.is_action_just_pressed(“ui_down”)):
$AnimatedSprite.play(“Sentandose”)
if $AnimatedSprite.frame ==3:
$AnimatedSprite.frames_loop(4,9)

:bust_in_silhouette: Reply From: Brinux

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")

thank you. It works perfectly, but I didn’t have to create the functions since it works in “is_on_floor ()”

thats is the result:

if Input.is_action_just_pressed("ui_down"):
		$AnimatedSprite.play("Sentandose")
		yield ($AnimatedSprite, "animation_finished")
		$AnimatedSprite.play("Sentado")

skylabelmho | 2019-08-15 21:32