Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | maxiproduksiyon |
Hello. It takes a long time for the game to restart when the player dies. (I am testing on my mobile phone)
New game button:
BackgroundLoad.load_scene(“res://src/Levels/Level01.tscn”)
The following loading bar works globally with BackgroundLoad.
Restart button:
get_tree().reload_current_scene()
Portal.gd :
When a player enters the portal, the following code is used to switch to the next level.
get_tree().change_scene(“res://src/Levels/Level0”+ str(newscene) +“.tscn”)
I am restarting the game using this code. and when the button is clicked, the game reloads in 5-8 seconds. The waiting time is very long when I try it on a mobile phone. I added loading bar to the first level and for the saved chapters. But I can’t add this code at Loading bar.
The godot logo is waiting for a very long time at the opening. I could not add loading bar at first boot.
Can you suggest a solution that will speed up the game for opening, restarting and transitioning levels?
extends Node2D
const SIMULATED_DELAY_SEC = 0.1
var thread = null
onready var progress = $Node2D/Progress
func _ready() -> void:
get_tree().paused = false
#if admanager.reklamkaldir == false:
#admanager.showBanner()
get_node("main-arka2").visible = false
get_node("Node2D/loading").visible = false
get_node("Node2D/oyunlogo").visible = false
progress.hide()
func _thread_load(path):
var ril = ResourceLoader.load_interactive(path)
assert(ril)
var total = ril.get_stage_count()
# Call deferred to configure max load steps.
progress.call_deferred("set_max", total)
var res = null
while true: #iterate until we have a resource
get_tree().paused = true
if admanager.reklamkaldir == false:
admanager.showBanner()
# Update progress bar, use call deferred, which routes to main thread.
progress.call_deferred("set_value", ril.get_stage())
# Simulate a delay.
#OS.delay_msec(int(SIMULATED_DELAY_SEC))
#OS.delay_msec(int(SIMULATED_DELAY_SEC * 1000.0))
# Poll (does a load step).
var err = ril.poll()
# If OK, then load another one. If EOF, it' s done. Otherwise there was an error.
if err == ERR_FILE_EOF:
# Loading done, fetch resource.
res = ril.get_resource()
break
elif err != OK:
# Not OK, there was an error.
print("There was an error loading")
break
# Send whathever we did (or did not) get.
call_deferred("_thread_done", res)
func _thread_done(resource):
assert(resource)
# Always wait for threads to finish, this is required on Windows.
thread.wait_to_finish()
# Hide the progress bar.
get_node("main-arka2").visible = false
progress.hide()
get_node("Node2D/loading").visible = false
get_node("Node2D/oyunlogo").visible = false
#get_node("loading").visible = false
# Instantiate new scene.
var new_scene = resource.instance()
# Free current scene.
get_tree().current_scene.free()
get_tree().current_scene = null
# Add new one to root.
get_tree().root.add_child(new_scene)
# Set as current scene.
get_tree().current_scene = new_scene
progress.visible = false
get_node("main-arka2").visible = false
get_node("Node2D/loading").visible = false
get_node("Node2D/oyunlogo").visible = false
if admanager.reklamkaldir == false:
admanager.hideBanner()
func load_scene(path):
thread = Thread.new()
thread.start( self, "_thread_load", path)
#raise() # Show on top.
progress.visible = true
get_node("main-arka2").visible = true
get_node("Node2D/loading").visible = true
get_node("Node2D/oyunlogo").visible = true