ile-de-test/script/global.gd

47 lines
1.3 KiB
GDScript

extends Node
const game_scenes = {
"scene_ile1_path": "res://scenes/iledetest.tscn"
}
var load_screen = preload("res://scenes/interface/loading_screen.tscn")
func load_scene(current_scene, next_scene):
var load_scene_instance = load_screen.instantiate()
get_tree().get_root().call_deferred("add_child", load_scene_instance)
var load_path: String
if game_scenes.has(next_scene):
load_path = game_scenes[next_scene]
else:
load_path = next_scene
var load_next_scene
if ResourceLoader.exists(load_path):
load_next_scene = ResourceLoader.load_threaded_request(load_path)
if load_next_scene == null:
print("error no loading screen existe !")
return
await load_scene_instance.safe_to_load
current_scene.queue_free()
while true:
var load_progress = []
var load_status = ResourceLoader.load_threaded_get_status(load_path, load_progress)
match load_status:
0:
print("error 0")
return
1:
load_scene_instance.get_node("control_background/progressBar").value = load_progress[0]
2:
print("error 2")
return
3:
var next_scene_instance = ResourceLoader.load_threaded_get(load_path).instantiate()
get_tree().get_root().call_deferred("add_child", next_scene_instance)
load_scene_instance.progress_bar()
return