Always set player node on top of instanced nodes.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 9BitStrider
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?

:bust_in_silhouette: Reply From: 9BitStrider

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

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

Squatnet | 2019-08-04 09:53

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

Deepak Jogi | 2019-12-31 17:55