End of Chapter 3. Loading scene and new game button working!
This commit is contained in:
36
scripts/loader.gd
Normal file
36
scripts/loader.gd
Normal 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
|
||||
|
||||
|
||||
|
||||
1
scripts/loader.gd.uid
Normal file
1
scripts/loader.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b406e4rlci4u3
|
||||
15
scripts/title/title_screen.gd
Normal file
15
scripts/title/title_screen.gd
Normal file
@@ -0,0 +1,15 @@
|
||||
extends Control
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_new_game_button_pressed() -> void:
|
||||
Loader.loadScene(self, "res://scenes/game.tscn")
|
||||
1
scripts/title/title_screen.gd.uid
Normal file
1
scripts/title/title_screen.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bklj1ua1qok02
|
||||
16
scripts/ui/loading_screen.gd
Normal file
16
scripts/ui/loading_screen.gd
Normal file
@@ -0,0 +1,16 @@
|
||||
extends Control
|
||||
|
||||
@export var loadingBar: TextureProgressBar
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
Loader.LOADING_PROGRESS_UPDATED.connect(_on_progress_updated)
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_progress_updated(percentage: float) -> void:
|
||||
loadingBar.value = percentage
|
||||
1
scripts/ui/loading_screen.gd.uid
Normal file
1
scripts/ui/loading_screen.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d1ag1ag2bbhtx
|
||||
Reference in New Issue
Block a user