This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+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 (92 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 (8,580 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 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.