[Solved] programmatically instancing objects under the tilemap

araxtharaxth Posts: 5Member
edited July 31 in Programming

Apparently it was simple, modifying the z-index property gets the job done.

Hi community,

noob question here.

I have a scene where multiple objects are added manually and ordered in such manner to appear under the tilemap if appropriate by using the ordering in the scene menu. For the manually added objects such as the boat in the bellow screenshots, things are looking like they were supposed to. However , i am instancing the uboats (red placeholder, under the boat) programmatically and they always seem to be displayed over the tilemap.

the code for the sub instancing part looks like bellow:

    extends Node2D
    var myenemy = preload("res://dusmanulnevazut.tscn")
    onready var btimer = get_node("BoatTimer")

    func _on_BoatTimer_timeout():
        subrndvalue = randi() % 8

        var e = myenemy.instance()

        var dir = 1
        if subrndvalue == 0:
            e.position = $sub1.position
            dir = 1 
        elif subrndvalue == 1:
            e.position = $sub2.position
            dir = 1 
        elif subrndvalue == 2:
            e.position = $sub3.position
            dir = 1             
        elif subrndvalue == 3:
            e.position = $sub4.position
            dir = 1         
        elif subrndvalue == 4:
            e.position = $sub8.position
            dir = -1
        elif subrndvalue == 5:
            e.position = $sub6.position
            dir = -1        
        elif subrndvalue == 6:
            e.position = $sub5.position
            dir = -1        
        elif subrndvalue == 7:
            e.position = $sub7.position
            dir = -1

basically a new sub is spawned at a certain position with a certain direction once the timer node ticks (set in a loo).

I'd rather have these subs shown behind the water tilemap and i don't know what i am missing in the big picture.

Thank you in advance.

Best regards

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file