Move loading demos to their own folder

This commit is contained in:
Aaron Franke
2020-01-28 14:19:42 -05:00
parent c6922db2a1
commit 04d86775da
47 changed files with 13 additions and 17 deletions

View File

@@ -0,0 +1,33 @@
extends Node
# 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):
# 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.
get_tree().get_current_scene().free()
# Load new scene
var packed_scene = ResourceLoader.load(path)
# Instance the new scene
var instanced_scene = packed_scene.instance()
# 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)

View File

@@ -0,0 +1,36 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
_global_script_classes=[ ]
_global_script_class_icons={
}
[application]
config/name="Autoload (Singletons)"
run/main_scene="res://scene_a.tscn"
[autoload]
global="res://global.gd"
[display]
window/stretch/mode="2d"
window/stretch/aspect="expand"
[gdnative]
singletons=[ ]
[memory]
multithread/thread_rid_pool_prealloc=60

View File

@@ -0,0 +1,4 @@
extends Panel
func _on_goto_scene_pressed():
get_node("/root/global").goto_scene("res://scene_b.tscn")

View File

@@ -0,0 +1,28 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scene_a.gd" type="Script" id=1]
[node name="SceneA" type="Panel"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 2
size_flags_vertical = 2
script = ExtResource( 1 )
[node name="Label" type="Label" parent="."]
margin_left = 64.0
margin_top = 48.0
margin_right = 104.0
margin_bottom = 62.0
size_flags_vertical = 0
text = "This is scene A."
[node name="GoToSceneB" type="Button" parent="."]
margin_left = 64.0
margin_top = 128.0
margin_right = 192.0
margin_bottom = 160.0
size_flags_horizontal = 2
size_flags_vertical = 2
text = "Go to Scene B"
[connection signal="pressed" from="GoToSceneB" to="." method="_on_goto_scene_pressed"]

View File

@@ -0,0 +1,4 @@
extends Panel
func _on_goto_scene_pressed():
get_node("/root/global").goto_scene("res://scene_a.tscn")

View File

@@ -0,0 +1,28 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scene_b.gd" type="Script" id=1]
[node name="SceneB" type="Panel"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 2
size_flags_vertical = 2
script = ExtResource( 1 )
[node name="Label" type="Label" parent="."]
margin_left = 64.0
margin_top = 48.0
margin_right = 164.0
margin_bottom = 62.0
size_flags_vertical = 0
text = "This is scene B."
[node name="GoToSceneA" type="Button" parent="."]
margin_left = 64.0
margin_top = 128.0
margin_right = 192.0
margin_bottom = 160.0
size_flags_horizontal = 2
size_flags_vertical = 2
text = "Go to Scene A"
[connection signal="pressed" from="GoToSceneA" to="." method="_on_goto_scene_pressed"]