Hi there!
I have the following problem: I have a pause menu that allows you to exit back to the main menu of my game. The problem is that this needs to remove all displayobjects and timers (and several eventlisteners), obviously, to close the current screen, before opening the new screen.
This is a typical situation. However, I don’t know in which part of my game this function will be called, so it is hard for me to know which displayObjects actually exist at that moment, making it impossible to know which ones to remove.
Is there a way to know or see how many display objects exist on the stage? I’ve tried display.numChildren but this doesn’t work.
So basically what I need to be able to do is remove all displayobjects, without actually knowing how many exist at that time, nor what their names are.
Something likes this would be perfect but doesn’t work of course:
for i = 1, display.numChildren
display[i]:removeSelf()
end
This would work for other displayGroups, but not for the stage, alas.
Or are there other ways to do this? One thing I can think of is adding every displayObject i add to a special table as well, and going over the contents of this table to delete them, but that sounds very convoluted, to be honest. [import]uid: 70134 topic_id: 19686 reply_id: 319686[/import]
[import]uid: 52491 topic_id: 19686 reply_id: 76564[/import]