summaryrefslogtreecommitdiff
path: root/demos/misc/autoload/global.gd
diff options
context:
space:
mode:
Diffstat (limited to 'demos/misc/autoload/global.gd')
-rw-r--r--demos/misc/autoload/global.gd23
1 files changed, 23 insertions, 0 deletions
diff --git a/demos/misc/autoload/global.gd b/demos/misc/autoload/global.gd
new file mode 100644
index 0000000000..d9fa308a2f
--- /dev/null
+++ b/demos/misc/autoload/global.gd
@@ -0,0 +1,23 @@
+extends Node
+
+
+var current_scene = null
+
+
+func goto_scene(scene):
+ #load new scene
+ var s = ResourceLoader.load(scene)
+ #queue erasing old (don't use free because that scene is calling this method)
+ current_scene.queue_free()
+ #instance the new scene
+ current_scene = s.instance()
+ #add it to the active scene, as child of root
+ get_scene().get_root().add_child(current_scene)
+
+
+func _ready():
+ # get the current scene
+ # it is always the last child of root,
+ # after the autoloaded nodes
+ var root = get_scene().get_root()
+ current_scene = root.get_child( root.get_child_count() -1 )