diff options
Diffstat (limited to 'demos/misc/autoload')
-rw-r--r-- | demos/misc/autoload/engine.cfg | 8 | ||||
-rw-r--r-- | demos/misc/autoload/global.gd | 23 | ||||
-rw-r--r-- | demos/misc/autoload/scene_a.gd | 17 | ||||
-rw-r--r-- | demos/misc/autoload/scene_a.scn | bin | 0 -> 1459 bytes | |||
-rw-r--r-- | demos/misc/autoload/scene_b.gd | 17 | ||||
-rw-r--r-- | demos/misc/autoload/scene_b.scn | bin | 0 -> 1448 bytes |
6 files changed, 65 insertions, 0 deletions
diff --git a/demos/misc/autoload/engine.cfg b/demos/misc/autoload/engine.cfg new file mode 100644 index 0000000000..c6ad023013 --- /dev/null +++ b/demos/misc/autoload/engine.cfg @@ -0,0 +1,8 @@ +[application] + +name="Autoload (Singletons)" +main_scene="res://scene_a.scn" + +[autoload] + +global="res://global.gd" 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 ) diff --git a/demos/misc/autoload/scene_a.gd b/demos/misc/autoload/scene_a.gd new file mode 100644 index 0000000000..21a6a84eb9 --- /dev/null +++ b/demos/misc/autoload/scene_a.gd @@ -0,0 +1,17 @@ + +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_a.scn b/demos/misc/autoload/scene_a.scn Binary files differnew file mode 100644 index 0000000000..61727a57ba --- /dev/null +++ b/demos/misc/autoload/scene_a.scn diff --git a/demos/misc/autoload/scene_b.gd b/demos/misc/autoload/scene_b.gd new file mode 100644 index 0000000000..4a88fddda9 --- /dev/null +++ b/demos/misc/autoload/scene_b.gd @@ -0,0 +1,17 @@ + +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 diff --git a/demos/misc/autoload/scene_b.scn b/demos/misc/autoload/scene_b.scn Binary files differnew file mode 100644 index 0000000000..ae09eeff88 --- /dev/null +++ b/demos/misc/autoload/scene_b.scn |