From c53b4e06eb5d1f1731085b829cba31b4a821173c Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Thu, 6 Feb 2020 21:46:49 +0100 Subject: [PATCH] updated the start scene to perform background loading --- start.gd | 27 ++++++++++++++++++++++----- start.tscn | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/start.gd b/start.gd index c447855..80df764 100644 --- a/start.gd +++ b/start.gd @@ -1,10 +1,27 @@ extends Control -func _ready(): - call_deferred("change_scene") +var loader -func change_scene(): +func _ready(): + var path : String if Directory.new().file_exists("res://material_maker/main_window.tscn"): - get_tree().change_scene("res://material_maker/main_window.tscn") + path = "res://material_maker/main_window.tscn" else: - get_tree().change_scene("res://demo/demo.tscn") + path = "res://demo/demo.tscn" + loader = ResourceLoader.load_interactive(path) + if loader == null: # check for errors + print("error") + queue_free() + +func _process(delta): + var err = loader.poll() + if err == ERR_FILE_EOF: + var resource = loader.get_resource() + get_node("/root").add_child(resource.instance()) + queue_free() + elif err == OK: + var progress = float(loader.get_stage()) / loader.get_stage_count() + $VBoxContainer/ProgressBar.value = 100.0*progress + else: # error during loading + print("error") + queue_free() diff --git a/start.tscn b/start.tscn index 2a7cddd..0086ba8 100644 --- a/start.tscn +++ b/start.tscn @@ -1,11 +1,39 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://start.gd" type="Script" id=1] +[ext_resource path="res://rodz_labs_logo.png" type="Texture" id=2] -[node name="Start" type="Control"] +[node name="Start" type="Panel"] anchor_right = 1.0 anchor_bottom = 1.0 script = ExtResource( 1 ) + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +anchor_left = 0.5 +anchor_right = 0.5 +anchor_bottom = 1.0 +margin_left = -128.0 +margin_right = 128.0 +alignment = 1 __meta__ = { "_edit_use_anchors_": false } + +[node name="TextureRect" type="TextureRect" parent="VBoxContainer"] +margin_top = 214.0 +margin_right = 256.0 +margin_bottom = 470.0 +texture = ExtResource( 2 ) +stretch_mode = 4 + +[node name="Label" type="Label" parent="VBoxContainer"] +margin_top = 474.0 +margin_right = 256.0 +margin_bottom = 488.0 +text = "Loading..." +align = 1 + +[node name="ProgressBar" type="ProgressBar" parent="VBoxContainer"] +margin_top = 492.0 +margin_right = 256.0 +margin_bottom = 506.0