0
votes

I have a quick question on removing objects. If you have something like:

  local game = display.newGroup()

  local ground = display.newImageRect("ground.png", 1000, 100)
  game:insert(ground)

  local wheel = display.newCircle(0, 0, 30)
  game:insert( wheel )

Would it be possible to remove all of the objects in the game group at once, or would I have to remove both objects separately? Thanks for your help!

2
have you looked at the "Group Removal" section of docs.coronalabs.com/guide/media/displayObjects/index.html#TOC? I must say it wasn't obvious to find, for some reason there is no link to this from the GroupObject page. - Oliver

2 Answers

3
votes

simply do:

game:removeSelf()
game = nil

First one removes all Corona stuff, second one cleans the 'game' table. But make sure you don't have any active transitions on the object.

2
votes
while middleGroup.numChildren > 0 do
        local child = middleGroup[1]
        if child then child:removeSelf() end
        print("middleGroup.numChildren" , middleGroup.numChildren )
    end

always remove first children nutil all children removed.