Easy enough, if you want to clean the coins only you just create a group and insert them into a group each time one is created:
spawnTrue = true;
coin = {}
allCoins = display.newGroup()
i = 1
function getCoins(event)
if event.phase == "ended" then
test = event.target
test:removeSelf()
test = nil
end
end
function spawnStuff( event )
if spawnTrue == true then
coin[i] = display.newCircle( 0, 0, 15 )
coin[i]:setFillColor( 255, 255, 0 )
coin[i].x = math.random( 0, 320 )
coin[i].y = math.random( 0, 320 )
allCoins:insert(coin[i])
coin[i]:addEventListener( "touch", getCoins )
i = i + 1
end
end
spawnBalls = timer.performWithDelay( 500, spawnStuff, 0 )
function killCoins( event )
if event.phase == "ended" then
allCoins:removeSelf()
allCoins = nil
allCoins = display.newGroup()
end
end
button = display.newRect( 150, 150, 50, 50)
button:addEventListener( "touch", killCoins )
The reason why I gave you such a short killCoins function is to show you that after you kill the entire group you have to recreate it so that you don’t get an error from your spawnCoin function trying to insert the coins into a group that doesn’t exist anymore. So make sure you recreate it after. A timer.pause would probably go in there to, to stop the coins from being created until you are ready again. [import]uid: 77199 topic_id: 29445 reply_id: 118319[/import]