Better Z-ordering (toFront, toBack)

I’m trying to find a way to do more precise positioning on the z-axis.

Currently, as far as I can tell, we’re limited to toFront() and toBack()

It would be great to have more granular control over z-order and be able to:

  1. Assign a numerical order of object positions.
  2. Swap the z-order of two objects
  3. Return the z-order of two objects
  4. Assign a ‘relative’ z-order (based on another object or group)

Or is this possible now, and I’m missing something?

[import]uid: 40285 topic_id: 9469 reply_id: 309469[/import]

Well, you can actually (kinda) but it’s easy to miss it. The z-order is equivalent to the index in a display group / stage.
So here is how to do it (not tested, so be warned):
[lua]1)
local group1 = display.newGroup()
group1.zindex = 1 – start at 1!

local group2 = display.newGroup()
group2.zindex = 2

local sprite1 = display.newImage(…)
sprite1.zindex = 1

local sprite2 = display.newImage(…)
sprite2.zindex = 2

local sprite3 = display.newImage(…)
sprite3.zindex = 3

group2:insert(sprite1)
group2:insert(sprite2)
group2:insert(sprite3)

group2:insert(1,sprite2)
sprite2.zindex = 1

group2:insert(2,sprite1)
sprite1.zindex = 2

print(sprite1.zindex)
print(sprite2.zindex)[/lua]

Obiously, you can write some simple functions to handle this as it would become irritating rather fast. [import]uid: 51516 topic_id: 9469 reply_id: 34651[/import]

I’ve not seen the zindex property before, thanks. Is that mentioned anywhere in the documentation? [import]uid: 12108 topic_id: 9469 reply_id: 34671[/import]

Fantastic. Using group index #'s should do the trick. I hadn’t realized that the group index # was actually the display order. Thanks Seth.
[import]uid: 40285 topic_id: 9469 reply_id: 34677[/import]

@jhocking: there is no zindex. It’s just a property to store the index in the group for retrieval. Name it “bananas” if you feel like it.

@jroven0: you’re welcome [import]uid: 51516 topic_id: 9469 reply_id: 34688[/import]