+1 vote

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:
The following loading bar works globally with BackgroundLoad.

Restart button:

Portal.gd :
When a player enters the portal, the following code is used to switch to the next level.

gettree().changescene("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
var thread = null
onready var progress = $Node2D/Progress
func _ready() -> void:
    get_tree().paused = false
    #if admanager.reklamkaldir == false:
    get_node("main-arka2").visible = false
    get_node("Node2D/loading").visible = false
    get_node("Node2D/oyunlogo").visible = false

func _thread_load(path):
    var ril = ResourceLoader.load_interactive(path)
    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:
        # 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 * 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()
        elif err != OK:
            # Not OK, there was an error.
            print("There was an error loading")
    # Send whathever we did (or did not) get.
    call_deferred("_thread_done", res)

func _thread_done(resource):
    # Always wait for threads to finish, this is required on Windows.
    # Hide the progress bar.
    get_node("main-arka2").visible = false
    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 = null
    # Add new one to root.
    # 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:

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
in Engine by (43 points)

1 Answer

0 votes

Well since the restarting code simply re-loads the level you could try 2 things.

1 simply make the levels load faster in the first place which would decrease the time needed to start a level and restart a level.

And 2, try making it so that when the level restarts, rather than reloading the whole thing, instead try simply resetting it, by re-spawning dead enemy's, teleporting the player back to spawn, and such. That would make it so that rather than reloading the whole level, you simply need to reset it, which minimizes reloading, and unloading.

by (573 points)

Hello. Thank's for the information.
I tried to experiment with your second answer. Actually I understood the logic. but I am having trouble applying.

when the player and the enemy die, I do queuefree () to delete them from the scene.
I wrote the following code instead of reload scene to understand. The camera is attached to the player. When I press restart, only tileset appears on the scene. the camera slides down endlessly. players and enemies do not appear. it does not appear in other non-spawning entities. they were not deleted after all.
What is the problem? Could the code below be wrong? Or is it wrong to add queue
free () when the player dies?

I have prepared 17 levels now. All levels have separate enemy names and separate starting positions. Will I have to create all of them one by one?

    var playerscene = load("res://src/Actors/Player.tscn")
    var player = playerscene.instance()
    var enemyscene = load("res://src/Actors/Enemy.tscn")
    var enemy = enemyscene.instance()
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.