s4m_ur4i Posted October 12, 2018 Share Posted October 12, 2018 Hey, when I assign setDepth(number) to Groups and Tilemaps, it seems not to work. Only after setting setDepth(number) on an already added sprite, it works. Any Ideas on it? Complete code below. // Tilemaps already created // # Configure z indexes layer.background.setDepth(0); //dynamic tilemap layer layer.midground.setDepth(1); //dynamic tilemap layer layer.objects.setDepth(2); // group layer.enemies.setDepth(3); // group layer.player.setDepth(4); // group layer.ground.setDepth(5); //dynamic tilemap layer layer.effects.setDepth(6); // group layer.water.setDepth(7); //dynamic tilemap layer //later on const SPRITE = this.add.sprite(0,0,'player') layer.player.add(SPRITE); //result: SPRITE is not in front of layer.background .. // BUT when I also write: const SPRITE = this.add.sprite(0,0,'player') layer.player.add(SPRITE); SPRITE.setDepth(0); // Now the sprite is before layer.background... ? Link to comment Share on other sites More sharing options...
rich Posted October 12, 2018 Share Posted October 12, 2018 Groups in v3 don't work the same as in v2, they're not containers. If you call Group.setDepth it will (as the docs say) immediately set the depth value of each child. If it has no children, or a child is added after you call this (like in the code above), it won't make any difference. s4m_ur4i 1 Link to comment Share on other sites More sharing options...
s4m_ur4i Posted October 12, 2018 Author Share Posted October 12, 2018 Ah okay, thanks for clarifying. I will have a look at containers now Link to comment Share on other sites More sharing options...
Recommended Posts