Jump to content

How to set z-index for a sprite


Stephen Persson
 Share

Recommended Posts

Add it last, and it will be on top...

If you will be adding other things later that need to be under it, then I would suggest using Phaser.Groups for layering...

 

Create 2 groups, add what you want to stay on top to the second group, and everything else to the first group...

 

This snippet has 3 groups, because I noticed you have a background image in your example...

// Groups for drawing layers
var back_layer = game.add.group();
var mid_layer = game.add.group();
var front_layer = game.add.group();
// It doesn't matter what order you add things to these groups, the draw order will be back, mid, front (unless you change it...)
back_layer.create(0, 0, "bg");
front_layer.create(0, 0, "front");
mid_layer.create(300, 200, "object1");
mid_layer.create(500, 400, "object2");
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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