diff options
Diffstat (limited to 'demos/misc/autoload')
-rw-r--r-- | demos/misc/autoload/global.gd | 20 | ||||
-rw-r--r-- | demos/misc/autoload/scene_a.gd | 3 | ||||
-rw-r--r-- | demos/misc/autoload/scene_a.scn | bin | 1459 -> 1660 bytes | |||
-rw-r--r-- | demos/misc/autoload/scene_b.gd | 3 | ||||
-rw-r--r-- | demos/misc/autoload/scene_b.scn | bin | 1448 -> 1639 bytes |
5 files changed, 11 insertions, 15 deletions
diff --git a/demos/misc/autoload/global.gd b/demos/misc/autoload/global.gd index d1bd45461f..126cbc0ab7 100644 --- a/demos/misc/autoload/global.gd +++ b/demos/misc/autoload/global.gd @@ -1,35 +1,33 @@ extends Node - +# member variables var current_scene = null func goto_scene(path): - # This function will usually be called from a signal callback, # or some other function from the running scene. # Deleting the current scene at this point might be # a bad idea, because it may be inside of a callback or function of it. # The worst case will be a crash or unexpected behavior. - + # The way around this is deferring the load to a later time, when # it is ensured that no code from the current scene is running: - + call_deferred("_deferred_goto_scene",path) func _deferred_goto_scene(path): - # Immediately free the current scene, - # there is no risk here. + # there is no risk here. current_scene.free() - + # Load new scene var s = ResourceLoader.load(path) - + # Instance the new scene current_scene = s.instance() - + # Add it to the active scene, as child of root get_tree().get_root().add_child(current_scene) @@ -38,6 +36,6 @@ func _ready(): # Get the current scene, the first time. # it is always the last child of root, # after the autoloaded nodes. - + var root = get_tree().get_root() - current_scene = root.get_child( root.get_child_count() -1 ) + current_scene = root.get_child(root.get_child_count() - 1) diff --git a/demos/misc/autoload/scene_a.gd b/demos/misc/autoload/scene_a.gd index 21a6a84eb9..b95ce7dc6e 100644 --- a/demos/misc/autoload/scene_a.gd +++ b/demos/misc/autoload/scene_a.gd @@ -5,13 +5,12 @@ extends Panel # 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_a.scn b/demos/misc/autoload/scene_a.scn Binary files differindex 61727a57ba..eff314e29d 100644 --- a/demos/misc/autoload/scene_a.scn +++ b/demos/misc/autoload/scene_a.scn diff --git a/demos/misc/autoload/scene_b.gd b/demos/misc/autoload/scene_b.gd index 4a88fddda9..599058848b 100644 --- a/demos/misc/autoload/scene_b.gd +++ b/demos/misc/autoload/scene_b.gd @@ -5,13 +5,12 @@ extends Panel # 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 diff --git a/demos/misc/autoload/scene_b.scn b/demos/misc/autoload/scene_b.scn Binary files differindex ae09eeff88..4cdb03e90e 100644 --- a/demos/misc/autoload/scene_b.scn +++ b/demos/misc/autoload/scene_b.scn |