I would simply use a group or groups to handle this and make them children of the scene group
-
Make a local a the top of your scene file called contentGroup
local contentGroup
-
In create() method, create the group and insert it into scenegroup::
contentGroup = display.newGroup() self.view:insert(contentGroup)
-
Add all of your objects to ‘contentGroup’
diplay.newCircle( contentGroup, 10, 10, 10) …
-
When you want to destroy the objects:
display.remove( contentGroup ) contentGroup = nil
PS - I strongly advice against using removeSelf(). It is perfectly suitable if you know exactly what you’re doing and you know for sure you made no mistakes, but if you make even a single mistake and call it twice on an object that has already been removed, you will crash your game.
So, instead of this:
obj:removeSelf()
I suggest always doing this:
display.remove( obj ) -- If obj is invalid, this safely does nothing
Before anyone says it, I know that a direct call to removeSelf() is ever so slightly faster, but that is not a valid reason to bypass the much safer call to ‘display.remove(obj)’.
If you’ are doing so many removals that the alternative safe remove is hurting you, you’ve got other problems already.