Jump to content

Group.setDepth and assigning a sprite to it, does not sort depth


Recommended Posts

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')

//result: SPRITE is not in front of layer.background ..

// BUT when I also write:

const SPRITE = this.add.sprite(0,0,'player')

// Now the sprite is before layer.background... ?
Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...