Configure autoload & input end
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
extends Control
|
||||
|
||||
var current_scene = null
|
||||
var loader = null
|
||||
var wait_frames = 1
|
||||
var time_max = 100 # msec
|
||||
|
||||
func _ready():
|
||||
print("[global#_ready] get root scene")
|
||||
var root = get_tree().get_root()
|
||||
current_scene = root.get_child(root.get_child_count() - 1)
|
||||
|
||||
func goto_scene(path):
|
||||
print("[global#goto_scene]")
|
||||
loader = ResourceLoader.load_interactive(path)
|
||||
if loader == null:
|
||||
print("Error loading ....")
|
||||
return
|
||||
|
||||
set_process(true)
|
||||
current_scene.queue_free()
|
||||
wait_frames = 1
|
||||
|
||||
func _process(_delta):
|
||||
print("[global#_process]")
|
||||
if loader == null:
|
||||
set_process(false)
|
||||
return
|
||||
|
||||
if wait_frames > 0:
|
||||
wait_frames -= 1
|
||||
|
||||
var tick = OS.get_ticks_msec()
|
||||
|
||||
# Use "time_max" to control for how long we block this thread
|
||||
while OS.get_ticks_msec() < tick + time_max:
|
||||
var err = loader.poll()
|
||||
|
||||
if err == ERR_FILE_EOF: # Finished loading.
|
||||
var resource = loader.get_resource()
|
||||
loader = null
|
||||
set_new_scene(resource)
|
||||
get_node("/root/Loading").hide()
|
||||
break
|
||||
elif err == OK:
|
||||
update_progress()
|
||||
else:
|
||||
print("[global#_process] Error loading")
|
||||
loader = null
|
||||
break
|
||||
|
||||
func update_progress():
|
||||
var progress = float(loader.get_stage()) / loader.get_stage_count()
|
||||
print("[global#update_progress] " + String(progress))
|
||||
get_node("/root/Loading").visible = true
|
||||
|
||||
func set_new_scene(scene_resource):
|
||||
print("[global#set_new_scene]")
|
||||
current_scene = scene_resource.instance()
|
||||
get_node("/root").add_child(current_scene)
|
||||
@@ -0,0 +1,35 @@
|
||||
[gd_scene format=2]
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 600.0
|
||||
rect_scale = Vector2( 1.00231, 1 )
|
||||
color = Color( 0, 0, 0, 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="ColorRect"]
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 600.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="ColorRect/CenterContainer"]
|
||||
margin_left = 479.0
|
||||
margin_top = 293.0
|
||||
margin_right = 544.0
|
||||
margin_bottom = 307.0
|
||||
|
||||
[node name="Label" type="Label" parent="ColorRect/CenterContainer/VBoxContainer"]
|
||||
margin_right = 65.0
|
||||
margin_bottom = 14.0
|
||||
text = "Loading ..."
|
||||
Reference in New Issue
Block a user