Sam Hogan
Sam Hogan

Reputation: 179

Corona SDK remove all objects in a group?

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!

Upvotes: 0

Views: 4206

Answers (2)

TimChang
TimChang

Reputation: 2417

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.

Upvotes: 2

Lukis
Lukis

Reputation: 652

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.

Upvotes: 3

Related Questions