Skip to content

Instantly share code, notes, and snippets.

@erodozer
Last active September 27, 2018 01:59
Show Gist options
  • Save erodozer/6d144fc1a92a41ef373f381ae2f03b60 to your computer and use it in GitHub Desktop.
Save erodozer/6d144fc1a92a41ef373f381ae2f03b60 to your computer and use it in GitHub Desktop.
Godot Scene Transition
extends Node
var next_scene = null
var is_ready setget _finish_transition
onready var anim = $Fader/AnimationPlayer
func _finish_transition(value):
if value:
is_ready = true
anim.play("Fade")
$Fader/Label.visible = false
get_tree().paused = false
func transition_menu(anim_name):
var tree = get_tree()
tree.change_scene(next_scene)
anim.disconnect("animation_finished", self, "transition_menu")
if is_ready:
self.is_ready = true
else:
$Fader/Label.visible = true
next_scene = null
func change_scene(goto, hold=false):
"""
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"
"""
next_scene = goto
anim.play_backwards("Fade")
anim.connect("animation_finished", self, "transition_menu")
is_ready = not hold
get_tree().paused = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment