Fixed loading screen transition sequencing

This commit is contained in:
Rob Kelly 2024-12-18 10:48:35 -07:00
parent 2583f39252
commit 6fad9af2a2
4 changed files with 41 additions and 13 deletions

View File

@ -58,28 +58,26 @@ func _ready() -> void:
##
## The loading screen will be shown until the scene is loaded.
func queue_scene(path: String) -> Promise:
if not loading_screen.visible:
loading_screen.show()
loading_screen.modulate = Color.WHITE
for child: Node in content.get_children():
child.queue_free()
return queue_load(path, ScenePromise.new()).finally(_finish_scene_load)
return queue_load(path, ScenePromise.new(), "PackedScene").finally(_finish_scene_load)
## Queue a resource to be loaded in the background.
##
## Returns a `Promise` which can be used to attach callbacks
## which will be called with the resource after it is loaded.
func queue_load(path: String, promise: Promise = null) -> Promise:
func queue_load(path: String, promise: Promise = null, type_hint: String = "") -> Promise:
if not promise:
promise = Promise.new()
_loading_resources[path] = promise
ResourceLoader.load_threaded_request(path)
ResourceLoader.load_threaded_request(path, type_hint)
return promise
func _unload_content() -> void:
for child: Node in content.get_children():
child.queue_free()
func _finish_scene_load(instance: Node) -> void:
content.add_child(instance)
instance.reparent(content)
@ -89,6 +87,9 @@ func _process(_delta: float) -> void:
if _loading_resources and not loading_screen.visible:
loader_transition.play("fade_in")
if loader_transition.is_playing():
return
for key: String in _loading_resources.keys():
match ResourceLoader.load_threaded_get_status(key):
ResourceLoader.THREAD_LOAD_LOADED:

View File

@ -38,7 +38,7 @@ tracks/1/keys = {
[sub_resource type="Animation" id="Animation_2c1ud"]
resource_name = "fade_in"
length = 0.4
length = 0.2
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
@ -58,11 +58,25 @@ tracks/1/path = NodePath(".:modulate")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.4),
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 1)]
}
tracks/2/type = "method"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("%RootControl/..")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0.2),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": &"_unload_content"
}]
}
[sub_resource type="Animation" id="Animation_xbqy2"]
resource_name = "fade_out"
@ -114,6 +128,7 @@ grow_vertical = 2
[node name="LoadingScreen" type="Control" parent="RootControl"]
unique_name_in_owner = true
process_mode = 3
z_index = 128
layout_mode = 1
anchors_preset = 15

View File

@ -125,6 +125,18 @@ tracks/0/keys = {
"update": 1,
"values": [false]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:modulate")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 1)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_s1eyj"]
_data = {

View File

@ -1480,7 +1480,7 @@ grow_horizontal = 2
grow_vertical = 2
[node name="PressStart" type="Label" parent="Menu"]
modulate = Color(1, 1, 1, 0.997997)
modulate = Color(1, 1, 1, 0.0282702)
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5