Update loading demos for 4.0 (#776)

This commit is contained in:
Jonathan Nicholl
2022-12-13 10:51:04 -05:00
committed by GitHub
parent 1b2ce74a39
commit 095beddcb9
133 changed files with 728 additions and 1703 deletions

View File

@@ -4,7 +4,7 @@ This demo shows how to use autoloads to change between scenes.
Language: GDScript
Renderer: Vulkan Mobile
Renderer: Mobile
Check out this demo on the asset library: https://godotengine.org/asset-library/asset/529

View File

@@ -1,10 +1,10 @@
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
# Changing scenes is most easily done using the functions change_scene_to_file
# and change_scene_to_packed of the SceneTree. This script demonstrates how to
# change scenes without those helpers.
func goto_scene(path):
func goto_scene(path: String):
# 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
@@ -13,21 +13,20 @@ func goto_scene(path):
# 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)
_deferred_goto_scene.call_deferred(path)
func _deferred_goto_scene(path):
# Immediately free the current scene, there is no risk here.
get_tree().get_current_scene().free()
func _deferred_goto_scene(path: String):
# Immediately free the current scene. There is no risk here because the
# call to this method is already deferred.
get_tree().current_scene.free()
# Load new scene
var packed_scene = ResourceLoader.load(path)
var packed_scene := ResourceLoader.load(path) as PackedScene
# Instance the new scene
var instanced_scene = packed_scene.instantiate()
var instanced_scene := packed_scene.instantiate()
# Add it to the scene tree, as direct child of root
get_tree().get_root().add_child(instanced_scene)
get_tree().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)
get_tree().current_scene = instanced_scene

View File

@@ -14,20 +14,16 @@ config/name="Autoload (Singletons)"
config/description="This demo shows how to use autoloads to change between scenes."
run/main_scene="res://scene_a.tscn"
config/features=PackedStringArray("4.0")
run/low_processor_mode=true
[autoload]
global="res://global.gd"
global="*res://global.gd"
[display]
window/stretch/mode="canvas_items"
window/stretch/aspect="expand"
[gdnative]
singletons=[]
window/vsync/vsync_mode=0
[rendering]
vulkan/rendering/back_end=1
renderer/rendering_method="mobile"

View File

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

View File

@@ -1,15 +1,19 @@
[gd_scene load_steps=2 format=3 uid="uid://bh2ylkcsgejgy"]
[gd_scene load_steps=2 format=3 uid="uid://6xgdg1bmya7c"]
[ext_resource type="Script" path="res://scene_a.gd" id="1"]
[node name="SceneA" type="Panel"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 2
size_flags_vertical = 2
script = ExtResource( "1" )
script = ExtResource("1")
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_left = 64.0
offset_top = 48.0
offset_right = 104.0
@@ -18,6 +22,7 @@ size_flags_vertical = 0
text = "This is scene A."
[node name="GoToSceneB" type="Button" parent="."]
layout_mode = 0
offset_left = 64.0
offset_top = 128.0
offset_right = 192.0

View File

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

View File

@@ -1,18 +1,19 @@
[gd_scene load_steps=2 format=3 uid="uid://pt77vxjf3uwe"]
[gd_scene load_steps=2 format=3 uid="uid://cmu1caqo7k7wy"]
[ext_resource type="Script" path="res://scene_b.gd" id="1"]
[node name="SceneB" type="Panel"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 2
size_flags_vertical = 2
script = ExtResource( "1" )
__meta__ = {
"_edit_use_anchors_": false
}
script = ExtResource("1")
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_left = 64.0
offset_top = 48.0
offset_right = 164.0
@@ -21,6 +22,7 @@ size_flags_vertical = 0
text = "This is scene B."
[node name="GoToSceneA" type="Button" parent="."]
layout_mode = 0
offset_left = 64.0
offset_top = 128.0
offset_right = 192.0

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB