0 votes
func spawn_objects():
    #Scan tilemap for objects.
    for cell in objects.get_used_cells():
        var id = objects.get_cellv(cell)
        var type = objects.tile_set.tile_get_name(id)
        #Get object ID and load into the level.
        if type in ['vert_gate', 'horiz_gate']:
            var c = load('res://scenes/'+type+'.tscn').instance()
            var pos = objects.map_to_world(cell)
            c.position = pos + (objects.cell_size / 2)

Using the above code to load stage object nodes into a stage without placing them manually. It works, but the instanced nodes are drawn ABOVE the player rather than underneath. What do I add to prevent this from happening?

enter image description here

in Engine by (211 points)

1 Answer

0 votes

Got it. Added it to the graphic layer as a child.

by (211 points)

If your player is in the same node as instanced children you could also do raise() to show it above its siblings

Well im trying to make an 2d infinite runner

The spawner and the object are 2 different scenes

But when i try to instance the background sprite the back ground ends up in front of the player

The player is already an instanced scene
But background gets instanced during run time somewhat like flappy bird

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.