Skip to content

Instantly share code, notes, and snippets.

@erodozer
Last active July 12, 2019 01:01
Show Gist options
  • Save erodozer/5c50b1fbddadab35f34ae006f771ff2e to your computer and use it in GitHub Desktop.
Save erodozer/5c50b1fbddadab35f34ae006f771ff2e to your computer and use it in GitHub Desktop.
Improved SceneManager
extends Node
onready var anim = $Fader/AnimationPlayer
func change_scene(next_scene, params=[]):
"""
Changes scene with a transition.
You can hold the fade back in transition if desired until
the next scene is in a state that is considered ready
"""
get_tree().paused = true
anim.play_backwards("Fade")
yield(anim, "animation_finished")
$Fader/Label.visible = true
var scene = get_tree().current_scene
if scene.has_method("_teardown"):
var state = scene._teardown()
if state and state is GDScriptFunctionState:
yield(state, "completed")
get_tree().change_scene(next_scene)
yield(get_tree(), "idle_frame")
scene = get_tree().current_scene
if scene.has_method("_setup"):
var state = scene._setup(params)
if state and state is GDScriptFunctionState:
yield(state, "completed")
$Fader/Label.visible = false
anim.play("Fade")
yield(anim, "animation_finished")
get_tree().paused = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment