End of Chapter 3. Loading scene and new game button working!

This commit is contained in:
2025-04-05 13:32:57 -03:00
parent 3f7a3cf979
commit e882e0e5fd
10 changed files with 110 additions and 4 deletions

36
scripts/loader.gd Normal file
View File

@@ -0,0 +1,36 @@
extends Node
signal LOADING_PROGRESS_UPDATED
@export var loadingScene: Node = preload("res://scenes/ui/loading_screen.tscn").instantiate()
var scenePath: String
func loadScene(caller: Node, path: String):
scenePath = path
get_tree().root.add_child(loadingScene)
ResourceLoader.load_threaded_request(scenePath)
print(scenePath)
caller.queue_free()
# 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:
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