+1 vote

I have an AnimationPlayer and sprites for one use in whole game. How can I use it to play animation for once without a loop?
this a piece of code that i tried to use in first scene:

extends Node2D



func _process(delta):
    $frisk/AnimationPlayer.play("wake_up")

    $frisk/AnimationPlayer.stop()

for others animations i use AnimationTree
and sorry for bad english

Godot version 3.2.3 stable
in Engine by (32 points)

2 Answers

+1 vote
Best answer

Your code should look a little more like this:
extends Node2D
func ready():
    $frisk/AnimationPlayer.play("wake
up")

OR, if you want to make it wait a little before it plays the anim, put yield(get_tree().create_timer(SECONDS_TO_WAIT), "timeout")
before the AnimPlayer.play() line.

by (77 points)
selected by
0 votes

AnimationPlayers will play animations without looping then by default. The loop option is on the top right of the AnimationPlayer docker.

by (7,769 points)

yes, but problem still isn't solve. how can i try to stop the AnimationPlayer at x second or something? like an "if-else" maybe

AnimationPlayers aren't really meant for arbitrary pausing. You'll probably have to check the current_animation_position property.

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.