0 votes

When I load the game with loading bar, 17 chapters are loaded instead of loading the first one. I am switching the scene in Portal2d. Do you have an idea for each partition to be loaded separately?

I am installing the 1. level with the code below:
BackgroundLoad.load_scene("res://src/Levels/Level01.tscn")

Portal2d.gd code :
var lastscene= PlayerData.lastlevel + 1
func onbodyentered(body: PhysicsBody2D):
gettree().changescene("res://src/Levels/Level0"+ str(lastscene) +".tscn")

I just want one level to be loaded. then load next level with portal2d.

BackgroundLoad bar code:

extends Node2D
const SIMULATED_DELAY_SEC = 0.1
var thread = null
onready var progress = $CanvasLayer/Progress
func _ready() -> void:
    get_tree().paused = false
    if admanager.reklamkaldir == false:
        admanager.showBanner()
    get_node("main-arka2").visible = false
    get_node("CanvasLayer/loading").visible = false
    get_node("CanvasLayer/oyunlogo").visible = false
    progress.hide()
    get_node("CanvasLayer/AnimatedSprite").visible = false


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 * 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("CanvasLayer/AnimatedSprite").visible = false
    get_node("CanvasLayer/loading").visible = false
    get_node("CanvasLayer/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("CanvasLayer/AnimatedSprite").visible = false
    get_node("CanvasLayer/loading").visible = false
    get_node("CanvasLayer/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("CanvasLayer/loading").visible = true
    get_node("CanvasLayer/oyunlogo").visible = true
    #get_node("AnimatedSprite").play("load")
    #get_node("AnimationPlayer").play("load")
    get_node("CanvasLayer/AnimatedSprite").visible = true
    #get_node("loading").visible = true
in Engine by (43 points)

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.