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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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