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)
            add_child(c)

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

asked Aug 2, 2019 in Engine by 9BitStrider (169 points)

1 Answer

0 votes

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

answered Aug 2, 2019 by 9BitStrider (169 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.