mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 15:00:09 +01:00
Move loading demos to their own folder
This commit is contained in:
33
loading/autoload/global.gd
Normal file
33
loading/autoload/global.gd
Normal 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)
|
||||
36
loading/autoload/project.godot
Normal file
36
loading/autoload/project.godot
Normal 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
|
||||
4
loading/autoload/scene_a.gd
Normal file
4
loading/autoload/scene_a.gd
Normal file
@@ -0,0 +1,4 @@
|
||||
extends Panel
|
||||
|
||||
func _on_goto_scene_pressed():
|
||||
get_node("/root/global").goto_scene("res://scene_b.tscn")
|
||||
28
loading/autoload/scene_a.tscn
Normal file
28
loading/autoload/scene_a.tscn
Normal 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"]
|
||||
4
loading/autoload/scene_b.gd
Normal file
4
loading/autoload/scene_b.gd
Normal file
@@ -0,0 +1,4 @@
|
||||
extends Panel
|
||||
|
||||
func _on_goto_scene_pressed():
|
||||
get_node("/root/global").goto_scene("res://scene_a.tscn")
|
||||
28
loading/autoload/scene_b.tscn
Normal file
28
loading/autoload/scene_b.tscn
Normal 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"]
|
||||
Reference in New Issue
Block a user