Losing Image When Swaping Groups

Hi there,

I am new to the SDK I am having trouble getting a car image contained in a group to display to screen, when I move it to another group called garage. It displays on the screen when I first create the group in the createCar function below, but as I click on the car the buttonListener function is triggered and when the code reaches the line garage:insert(x) the car image is removed from the screen. Although, if I click in the space where the car was the listener still fires.

How can I get objects stored in the garage group to display to the screen
Please see my simplified code below:

[code]
local garage = display.newGroup()

local buttonListener = function( event )
print(“in listener”)
local x = event.target
garage:insert(x)
end
function createCar()
local group = display.newGroup()
local carOriginal = display.newImage(“car_blue.png”)
group:insert( carOriginal, true )
group.x = 100
group.y = 100
group:addEventListener( “tap”, buttonListener )

end

createCar()

[/code] [import]uid: 9512 topic_id: 2639 reply_id: 302639[/import]

Well, I am not on a Mac but I’ll state some possible explanation…

Nothing goes wrong here. It’s just that you have not been introduced to the sorting system of display objects that Corona uses. It goes like this: Any display object you create is shown on top of others you have already created. The last created object is what you see on top of the display heap.

So, here you have firstly created the “garage” group and after that the “group” group. Both of them are objects, so they follow the rules I described above. The “group” is optically above “garage”. So when you move the car from “group” (front) to “garage” (back)it may be optically invisible, depending of what else you show on “group”. You can swap the z-orded of groups by calling :
stage=display.getCurrentStage()
stage:insert(garage)

This will re-insert garage in the stage (the super-group) so it will be the last added and so the one displayed at top.
If you want some additional material on groups, read a mini tutorial I have written and play with the comments to see how things work.

[import]uid: 7356 topic_id: 2639 reply_id: 7590[/import]

Thanks Magenda, that worked [import]uid: 9512 topic_id: 2639 reply_id: 7663[/import]