JJZAD,
try this snippet of code; cut and paste it into a new project and run it. tap the small rectangles and see how they move behind each other.
local CENTER\_X = display.contentWidth \* .5 local CENTER\_Y = display.contentHeight \* .5 local bg = display.newRect(CENTER\_X, CENTER\_Y, display.contentWidth, display.contentHeight) bg:setFillColor(.7,.2,.2) local greyImg = display.newRect(200,200,100, 100) greyImg:setFillColor(.2, .2, .2) greyImg.id = 1 local blueImg = display.newRect(250,250,100, 100) blueImg:setFillColor(.2, .2, .8) blueImg.id = 2 local greenImg = display.newRect(300,300,100, 100) greenImg:setFillColor(.2, .8, .2) greenImg.id = 3 local imgGroup = display.newGroup() imgGroup:insert(greyImg) imgGroup:insert(blueImg) imgGroup:insert(greenImg) local defaultImg = 2 local function onTouch(e) if e.phase == "ended" then -- first move the selected target to back, if that is what you want e.target:toBack() -- now reorder the images for i = 1, imgGroup.numChildren do -- you can loop thru the images and -- figure which order to place them in -- pushing the images to front or back end end return true end greyImg:addEventListener("touch", onTouch) blueImg:addEventListener("touch", onTouch) greenImg:addEventListener("touch", onTouch)
The key point is bg (background image) is not inserted into the display group. Both the background image and the display group (‘imgGroup’) are part of the stage. If you were to code : ’ imgGroup:toBack() ’ it will hide that group behind the bg image.
So as Rob mentioned (and in this example code), just add your images to a display group. Maybe give each a unique id, and then loop through the group of images to re-order them.
Hope this helps.