End of chapter 6. A lot of problems took to much time to solve. It was good to know better Godot internal mechanism.

This commit is contained in:
2025-04-06 18:07:29 -03:00
parent 909c385dee
commit db55b2af02
21 changed files with 202 additions and 70 deletions

View File

@@ -1,36 +1,32 @@
extends Node
signal LOADING_PROGRESS_UPDATED
@export var loadingScene: Node = preload("res://scenes/ui/loading_screen.tscn").instantiate()
signal LOADING_PROGRESS_UPDATED(percentage)
var scenePath: String
@export var loadingScene = preload("res://scenes/ui/loading_screen.tscn").instantiate()
func loadScene(caller: Node, path: String):
var scenePath
func loadScene(caller, path):
scenePath = path
get_tree().root.add_child(loadingScene)
ResourceLoader.load_threaded_request(scenePath)
#print(scenePath)
caller.queue_free()
func _process(delta):
if (scenePath != null):
var progress = []
var loaderStatus = ResourceLoader.load_threaded_get_status(scenePath, progress)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
if scenePath:
var progress: Array = []
var loaderStatus: ResourceLoader.ThreadLoadStatus = ResourceLoader.load_threaded_get_status(scenePath, progress)
if loaderStatus == ResourceLoader.ThreadLoadStatus.THREAD_LOAD_LOADED:
LOADING_PROGRESS_UPDATED.emit(progress[0])
if (loaderStatus == ResourceLoader.THREAD_LOAD_LOADED):
var loadedScene = ResourceLoader.load_threaded_get(scenePath).instantiate()
get_tree().root.remove_child(loadingScene)
get_tree().root.add_child(loadedScene)
scenePath = ""
elif loaderStatus == ResourceLoader.ThreadLoadStatus.THREAD_LOAD_IN_PROGRESS:
LOADING_PROGRESS_UPDATED.emit(progress[0])
else:
pass
scenePath = null