In my game, I have a need to remove all of the stage objects (for a new level). After I call the clean up code, I check the stage to see if there are any objects remaining. I’m using the following code:
print("Stage Objects: "…display.getCurrentStage().numChildren)
I’d like to loop through and get the names of all the objects still left in memory so that I can fix my clean up code to remove them (via object:removeSelf()). I tried to loop through the stage objects but it seems that the root stage is a container of all groups and objects and I can’t figure out how to print their names or ids to the console window. All of my object have a “name” property such as object.name that I set so that I can relate them back to the object.
Any help would be appreciated and save me time.
thanks,
Rob [import]uid: 38348 topic_id: 22876 reply_id: 322876[/import]
If you simply want to remove all the objects you can do so very easily like so;
[lua]display.setStatusBar (display.HiddenStatusBar)
local bg = display.newRect( 0, 0, 320, 480 )
bg:setFillColor(200, 0, 0)
local circle = {}
for i = 1, 6 do
circle[i] = display.newCircle( math.random(0,320), math.random(0,480), 30 )
end
local count = display.getCurrentStage().numChildren
local function cleanUp()
for i = 1, count do
display.getCurrentStage():remove(1)
end
end
timer.performWithDelay(2000, cleanUp, 1)[/lua]
Does this help?
Peach
[import]uid: 52491 topic_id: 22876 reply_id: 91404[/import]
Thanks for your post, Peach. I had done this in the past but was hoping I could avoid the black screen that results at the end of this operation.
I found and have removed all the objects but I was hoping to find a method that i could turn on when I find that I’m not removing an object.
What about a method for finding event listeners that are current at a given point in time, is there a way to view those in the console output?
thanks,
Rob [import]uid: 38348 topic_id: 22876 reply_id: 91837[/import]
I don’t believe so RE event listeners.
With cleanup, this would work with groups, or if the image/s you weren’t removing were the last ones added then you could also make that work.
Either of those could be used to prevent black screen
[import]uid: 52491 topic_id: 22876 reply_id: 91870[/import]
Good point. I’ll put the transition screen up and remove all of the items except the last item that was added. I like that idea.
thanks Peach.
Rob [import]uid: 38348 topic_id: 22876 reply_id: 91991[/import]
Not a problem, good luck with your project
[import]uid: 52491 topic_id: 22876 reply_id: 92123[/import]