Switching z-order in group

Is there a shorthand way to switch two display objects in a group?

I worked it out conceptually on paper and it looks like it takes a few steps, and requires a dummy object and knowing the indexes of the two switching objects. (Does that sound about right?)
On that note, is there an easy way to find the index number of that object instead of searching for it in the group?

Also I know there is a shorthand for switching the values of two variables but can’t find it. Know it?

Thanks! [import]uid: 117490 topic_id: 20755 reply_id: 320755[/import]

Reinserting an image into a group at an index will put it at that index and shift the other objects.

How you go about deciding which objects you want to flip is different issue. I’m not sure how to do that yet as there doesn’t seem to be an equivalent to indexOf for display objects.

Anyway, this shows how reinserting can switch positions of objects without having to dump them into dummy groups first:

[code]

local testgroup = display.newGroup()

local image1 = display.newImage(“img1.png”)
image1.x, image1.y = 100,100

local image2 = display.newImage(“img2.png”)
image2.x, image2.y = 105,105

local image3 = display.newImage(“img3.png”)
image3.x, image3.y = 110,110
testgroup:insert(image1)
testgroup:insert(image2)
testgroup:insert(image3)

local buttonHandler = function(evt)
if evt.target.id == “switch” then

testgroup:insert(3,image1)
testgroup:insert(1,image3)

end
end

local switchbutton = widget.newButton{
id = “switch”,
left = 100,
top = 300,
label = “switch em”,
cornerRadius = 8,
onRelease = buttonHandler
}

[/code] [import]uid: 120 topic_id: 20755 reply_id: 81584[/import]

What you could do aswell is to use either :toFront() / :toBack.

You could also give each object a Z-property and using a table-sort function and then reInserting them into the group with the given id. Sometimes that’s the way to go when having a Sidescroller with a bit of perspective where you need to have objects in the back- and foreground… [import]uid: 13097 topic_id: 20755 reply_id: 81667[/import]