Merge pull request #3048 from eska014/autoload-demo
Update Autoload demo
This commit is contained in:
commit
73153eadfa
|
@ -1,7 +1,9 @@
|
||||||
extends Node
|
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):
|
func goto_scene(path):
|
||||||
|
@ -18,20 +20,17 @@ func goto_scene(path):
|
||||||
|
|
||||||
|
|
||||||
func _deferred_goto_scene(path):
|
func _deferred_goto_scene(path):
|
||||||
# Immediately free the current scene,
|
# Immediately free the current scene, there is no risk here.
|
||||||
# there is no risk here.
|
get_tree().get_current_scene().free()
|
||||||
current_scene.free()
|
|
||||||
|
|
||||||
# Load new scene
|
# Load new scene
|
||||||
var s = ResourceLoader.load(path)
|
var packed_scene = ResourceLoader.load(path)
|
||||||
|
|
||||||
# Instance the new scene
|
# Instance the new scene
|
||||||
current_scene = s.instance()
|
var instanced_scene = packed_scene.instance()
|
||||||
|
|
||||||
# Add it to the active scene, as child of root
|
# Add it to the scene tree, as direct child of root
|
||||||
get_tree().get_root().add_child(current_scene)
|
get_tree().get_root().add_child(instanced_scene)
|
||||||
|
|
||||||
|
# Set it as the current scene, only after it has been added to the tree
|
||||||
func _ready():
|
get_tree().set_current_scene(instanced_scene)
|
||||||
# Get the current scene at the time of initialization
|
|
||||||
current_scene = get_tree().get_current_scene()
|
|
||||||
|
|
|
@ -1,16 +1,5 @@
|
||||||
|
|
||||||
extends Panel
|
extends Panel
|
||||||
|
|
||||||
# Member variables here, example:
|
|
||||||
# var a=2
|
|
||||||
# var b="textvar"
|
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
|
||||||
# Initalization here
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
func _on_goto_scene_pressed():
|
func _on_goto_scene_pressed():
|
||||||
get_node("/root/global").goto_scene("res://scene_b.scn")
|
get_node("/root/global").goto_scene("res://scene_b.scn")
|
||||||
pass # Replace with function body
|
|
||||||
|
|
|
@ -1,16 +1,5 @@
|
||||||
|
|
||||||
extends Panel
|
extends Panel
|
||||||
|
|
||||||
# Member variables here, example:
|
|
||||||
# var a=2
|
|
||||||
# var b="textvar"
|
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
|
||||||
# Initalization here
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
func _on_goto_scene_pressed():
|
func _on_goto_scene_pressed():
|
||||||
get_node("/root/global").goto_scene("res://scene_a.scn")
|
get_node("/root/global").goto_scene("res://scene_a.scn")
|
||||||
pass # Replace with function body
|
|
||||||
|
|
Loading…
Reference in a new issue