0 votes

My problem is really simple, but I can't wrap my head around it. What I'm trying to do is to play an animation, and then switch scenes. Here's the code that I want to improve:

extends Control

onready var animplayer = get_node("../../AnimationPlayer")

func _input_event(ev):
    if (ev.type==InputEvent.MOUSE_BUTTON and ev.button_index==BUTTON_LEFT and ev.pressed):
        animplayer.play("AnimationPlayer")
        get_node("/root/globals").setScene("res://Scenes/levelselect.scn")

func _ready():
    pass

I couldn't find a solution to my problem, so I came here. Thanks in advance!

in Engine by (172 points)
edited by

2 Answers

0 votes
Best answer

You can do it with signal.

animplayer.connect("finished", get_node("/root/globals"), "setScene", ["res://Scenes/levelselect.scn"])
animplayer.play("AnimationPlayer")
by (9,736 points)
selected by
+1 vote

You can call functions with your animation just by pressing the '+' in the bottom right corner in the animation setup. So if you just make a function in your script, then you can call that function when the animation is over.

by (152 points)
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.