Animation for one use

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

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

:bust_in_silhouette: Reply From: boston2029

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.

:bust_in_silhouette: Reply From: exuin

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

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

pafos_kota | 2021-04-10 16:42

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

exuin | 2021-04-10 17:12