summaryrefslogtreecommitdiff
path: root/demos/misc/autoload
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2015-12-13 10:10:18 +0100
committerRémi Verschelde <remi@verschelde.fr>2015-12-13 10:10:18 +0100
commit73153eadfa236d383b03a1a4f09992fd13823a96 (patch)
treeee1ddd741b1f4b8cbb0f5ef61672f18ac3bbe571 /demos/misc/autoload
parent8c005e2b73ee35ee3dea90ccbb076b313f0c0fc4 (diff)
parente7581a97e7c18d74addf818e55f7161a062e291a (diff)
Merge pull request #3048 from eska014/autoload-demo
Update Autoload demo
Diffstat (limited to 'demos/misc/autoload')
-rw-r--r--demos/misc/autoload/global.gd27
-rw-r--r--demos/misc/autoload/scene_a.gd11
-rw-r--r--demos/misc/autoload/scene_b.gd11
3 files changed, 13 insertions, 36 deletions
diff --git a/demos/misc/autoload/global.gd b/demos/misc/autoload/global.gd
index 2671b6f412..735995e806 100644
--- a/demos/misc/autoload/global.gd
+++ b/demos/misc/autoload/global.gd
@@ -1,7 +1,9 @@
extends Node
-# Member variables
-var current_scene = null
+
+# Changing scenes is most easily done using the functions `change_scene`
+# and `change_scene_to` of the SceneTree. This script demonstrates how to
+# change scenes without those helpers.
func goto_scene(path):
@@ -18,20 +20,17 @@ func goto_scene(path):
func _deferred_goto_scene(path):
- # Immediately free the current scene,
- # there is no risk here.
- current_scene.free()
+ # Immediately free the current scene, there is no risk here.
+ get_tree().get_current_scene().free()
# Load new scene
- var s = ResourceLoader.load(path)
+ var packed_scene = ResourceLoader.load(path)
# Instance the new scene
- current_scene = s.instance()
+ var instanced_scene = packed_scene.instance()
- # Add it to the active scene, as child of root
- get_tree().get_root().add_child(current_scene)
-
-
-func _ready():
- # Get the current scene at the time of initialization
- current_scene = get_tree().get_current_scene()
+ # Add it to the scene tree, as direct child of root
+ get_tree().get_root().add_child(instanced_scene)
+
+ # Set it as the current scene, only after it has been added to the tree
+ get_tree().set_current_scene(instanced_scene)
diff --git a/demos/misc/autoload/scene_a.gd b/demos/misc/autoload/scene_a.gd
index f9c39887b0..03da86d9a0 100644
--- a/demos/misc/autoload/scene_a.gd
+++ b/demos/misc/autoload/scene_a.gd
@@ -1,16 +1,5 @@
-
extends Panel
-# Member variables here, example:
-# var a=2
-# var b="textvar"
-
-
-func _ready():
- # Initalization here
- pass
-
func _on_goto_scene_pressed():
get_node("/root/global").goto_scene("res://scene_b.scn")
- pass # Replace with function body
diff --git a/demos/misc/autoload/scene_b.gd b/demos/misc/autoload/scene_b.gd
index fdf2287a04..dea8c4623f 100644
--- a/demos/misc/autoload/scene_b.gd
+++ b/demos/misc/autoload/scene_b.gd
@@ -1,16 +1,5 @@
-
extends Panel
-# Member variables here, example:
-# var a=2
-# var b="textvar"
-
-
-func _ready():
- # Initalization here
- pass
-
func _on_goto_scene_pressed():
get_node("/root/global").goto_scene("res://scene_a.scn")
- pass # Replace with function body