How do I setup a localGroup:clean()?

I’m really a newbie at this so can anybody show me in this code lines sample how to put a localGroup:clean

[code] module(…, package.seeall)

function new(params )
local localGroup = display.newGroup()

require( “ice” )
local physics = require(“physics”)
local ui = require(“ui”)
local gameUI = require(“gameUI”)
physics.start()
physics.setGravity(0, -1)
local scores = ice:loadBox( “scores” )

local high = scores:retrieve(“best”)
print(high)

display.setStatusBar( display.HiddenStatusBar )

local scoreText
local score = 0
local highscore
local button1
local runMode = true
local spawn = true
local touch = true
local gameOver = false
local bkg = display.newImage( “bkg.png” )
bkg.x = 160; bkg.y = 240
localGroup:insert(bkg)

local score_txt =display.newText("Score: ",0,0,nil,25)
score_txt.x = 160; score_txt.y = 440
score_txt:setTextColor(0,0,0)
score_txt.text = "Score: "… score
localGroup:insert(score_txt)

local spawnBall = function( event )
local t = event.target
local phase = event.phase
if touch == true then
if “began” == phase then
t:removeSelf() – destroy object
score = score + math.random( 1000 )
score_txt.text = "Score: "… score
end
– Stop further propagation of touch event
return true
end
end
local balls = {}
local group = display.newGroup()

local spawnBalloon = function()

ball = display.newImage( group, “balloon.png” )
ball.x = 60 + math.random( 160 )
ball.y = 550
physics.addBody( ball, { density=0.0, friction=0.1, bounce=0.1 } )
ball:addEventListener( “touch”, spawnBall )
balls[#balls + 1] = ball
if spawn == true then
end
end
bTimer = timer.performWithDelay(500, spawnBalloon, -1)

local function delete()
for i=group.numChildren,1,-1 do
local child = group[i]
if group[i].y < -100 then
display.remove(group[i]) – dont know about this part, try it
end
end
end

Runtime:addEventListener(“enterFrame”, delete)

local group2 = display.newGroup()

local spawnBalloon2 = function()
if spawn == true then
ball2 = display.newImage( group, “balloon2.png” )
ball2.x = 60 + math.random( 160 )
ball2.y = 550
physics.addBody( ball2, { density=0.0, friction=0.1, bounce=0.1 } )
ball2:addEventListener( “touch”, spawnBall )
balls[#balls + 1] = ball2
end
end
bTimer2 = timer.performWithDelay(800, spawnBalloon2, -1)

local function delete2()
for i=group.numChildren,1,-1 do
local child = group[i]
if group[i].y < -100 then
display.remove(group[i]) – dont know about this part, try it
end
end
end

Runtime:addEventListener(“enterFrame”, delete2)

local group3 = display.newGroup()

local spawnBalloon3 = function()
if spawn == true then
ball = display.newImage( group, “balloon3.png” )
ball.x = 60 + math.random( 160 )
ball.y = 550
physics.addBody( ball, { density=0.0, friction=0.1, bounce=0.1 } )
ball:addEventListener( “touch”, spawnBall )
balls[#balls + 1] = ball
end
end
bTimer3 = timer.performWithDelay(700, spawnBalloon3, -1)

local function delete3()
for i=group.numChildren,1,-1 do
local child = group[i]
if group[i].y < -100 then
display.remove(group[i]) – dont know about this part, try it
end
end
end

Runtime:addEventListener(“enterFrame”, delete3)

local group4 = display.newGroup()

local spawnBalloon4 = function()
if spawn == true then
ball = display.newImage( group, “balloon4.png” )
ball.x = 60 + math.random( 160 )
ball.y = 550
physics.addBody( ball, { density=0.0, friction=0.1, bounce=0.1 } )
ball:addEventListener( “touch”, spawnBall )
balls[#balls + 1] = ball
end
end
bTimer4 = timer.performWithDelay(600, spawnBalloon4, -1)

local function delete4()
for i=group.numChildren,1,-1 do
local child = group[i]
if group[i].y < -100 then
display.remove(group[i]) – dont know about this part, try it
end
end
end

Runtime:addEventListener(“enterFrame”, delete4)

local group5 = display.newGroup()

local spawnBalloon5 = function()
if spawn == true then
ball = display.newImage( group, “balloon5.png” )
ball.x = 60 + math.random( 160 )
ball.y = 550
physics.addBody( ball, { density=0.0, friction=0.1, bounce=0.1 } )
ball:addEventListener( “touch”, spawnBall )
balls[#balls + 1] = ball
end
end
bTimer5 = timer.performWithDelay(1100, spawnBalloon5, -1)

local function delete5()
for i=group.numChildren,1,-1 do
local child = group[i]
if group[i].y < -100 then
display.remove(group[i]) – dont know about this part, try it
end
end
end

Runtime:addEventListener(“enterFrame”, delete5)

local group6 = display.newGroup()

local spawnBalloon6 = function()
if spawn == true then
ball = display.newImage( group, “balloon6.png” )
ball.x = 60 + math.random( 160 )
ball.y = 550
physics.addBody( ball, { density=0.0, friction=0.1, bounce=0.1 } )
ball:addEventListener( “touch”, spawnBall )
balls[#balls + 1] = ball
end
end
bTimer6 = timer.performWithDelay(1300, spawnBalloon6, -1)

local function delete6()
for i=group.numChildren,1,-1 do
local child = group[i]
if group[i].y < -100 then
display.remove(group[i]) – dont know about this part, try it
end
end
end

Runtime:addEventListener(“enterFrame”, delete6)

local group7 = display.newGroup()

local spawnBalloon7 = function()
if spawn == true then
ball = display.newImage( group, “balloon7.png” )
ball.x = 60 + math.random( 160 )
ball.y = 550
physics.addBody( ball, { density=0.0, friction=0.1, bounce=0.1 } )
ball:addEventListener( “touch”, spawnBall )
balls[#balls + 1] = ball
end
end
bTimer7 = timer.performWithDelay(900, spawnBalloon7, -1)

local function delete7()
for i=group.numChildren,1,-1 do
local child = group[i]
if group[i].y < -100 then
display.remove(group[i]) – dont know about this part, try it
end
end
end

Runtime:addEventListener(“enterFrame”, delete7)

local bt = display.newImage (“pause.png”)
bt.x = 290
bt.y = 30
localGroup:insert(bt)

local bt2 = display.newImage (“pauseOver.png”)
bt2.x = bt.x
bt2.y = bt.y
bt2.isVisible = false
localGroup:insert(bt2)

local Pause = display.newText(“Pause”, 5, 0, “ArialRoundedMTBold”, 30)
Pause.x = 160
Pause.y = 110
Pause:setTextColor(0,0,0)
Pause.isVisible = false
localGroup:insert(Pause)

local Resume = display.newText(“Resume”, 5, 0, “ArialRoundedMTBold”, 25)
Resume.x = 160
Resume.y = 190
Resume:setTextColor(0,0,0)
Resume.isVisible = false
localGroup:insert(Resume)

local Quit = display.newText(“Quit”, 5, 0, “ArialRoundedMTBold”, 25)
Quit.x = 160
Quit.y = 270
Quit:setTextColor(0,0,0)
Quit.isVisible = false
localGroup:insert(Quit)

–Function for pause button
local function done ()
physics.start()
spawn = true
touch = true
bt.isVisible = true
bt2.isVisible = false
Quit.isVisible = false
Resume.isVisible = false
Pause.isVisible = false
result = timer.resume( timerID )
end
Resume:addEventListener(“tap”, done)

local function onClick(e)
if e.action == “clicked” then
if e.index == 1 then
director:changeScene (“balloon popper”, “fade”)

elseif e.index == 2 then
director:changeScene (“play”, “fade”)
timer.cancel(bTimer)
timer.cancel(bTimer2)
timer.cancel(bTimer3)
timer.cancel(bTimer4)
timer.cancel(bTimer5)
timer.cancel(bTimer6)
timer.cancel(bTimer7)
elseif e.index == 3 then
physics.start()
result = timer.resume( timerID )
timer.resume(bTimer)
timer.resume(bTimer2)
timer.resume(bTimer3)
timer.resume(bTimer4)
timer.resume(bTimer5)
timer.resume(bTimer6)
timer.resume(bTimer7)
end
end
end

– Display Alert

function bt:tap(e)
local alert = native.showAlert(“Paused Game”, “Balloon Popper”, {“Restart”, “Main Menu”, “Resume”}, onClick)
result = timer.pause( timerID )
physics.pause()
timer.pause(bTimer)
timer.pause(bTimer2)
timer.pause(bTimer3)
timer.pause(bTimer4)
timer.pause(bTimer5)
timer.pause(bTimer6)
timer.pause(bTimer7)
end
bt:addEventListener(“tap”, bt)
local count = 60

local time = display.newText( “60”, 5, 0, “ArialRoundedMTBold”, 40)
time:setTextColor( 0, 0, 0 )
localGroup:insert(time)

local timeDelay = 700

function time:timer( event )

count = count -1
self.text = count

if count <= 55 then

director:changeScene (“popover”)
timer.cancel(bTimer)
timer.cancel(bTimer2)
timer.cancel(bTimer3)
timer.cancel(bTimer4)
timer.cancel(bTimer5)
timer.cancel(bTimer6)
timer.cancel(bTimer7)
timer.cancel( event.source)

end
end

– Register to call t’s timer method 50 times
timerID = timer.performWithDelay( timeDelay, time, -1 )

local highText = display.newText("", 0,0,nil,30)
highText.x = display.contentWidth/2
highText.y = display.contentHeight/2
localGroup:insert(highText)
highText.text = "HighScore: "… scores:retrieve(“best”)

local function show_highScore()

scores:storeIfHigher( “best”, score )
scores:save()
local highText = display.newText("", 0,0,nil,30)
highText.x = display.contentWidth/2
highText.y = display.contentHeight/2

if score > high then
highText.text = "HighScore: "… scores:retrieve(“best”)
else

if score > high then
print(“new high score”)
highText.text = "HighScore: "… scores:retrieve(“best”)
end
end

end

timer.performWithDelay(60000, show_highScore, 1)

return localGroup
end
[/code]

What I’m trying to remove is balloons but they can’t be put in localGroup but in localGroup:clean function.

So can anybody please show me how it looks like having a localGroup:clean function in this code.

Thanks for help :slight_smile: [import]uid: 17058 topic_id: 19491 reply_id: 319491[/import]

I’ve got the problem
[import]uid: 17058 topic_id: 19491 reply_id: 75883[/import]

I think you have already fixed it but for reference:

function localGroup:clean()
localGroup:removeSelf()
localGroup = nil
end [import]uid: 79135 topic_id: 19491 reply_id: 75884[/import]

@andrewscott thanks for the help yeah I’ve got the problem solved

Also if you don’t mind to look at my forum for Making Side Scrolling games [import]uid: 17058 topic_id: 19491 reply_id: 75889[/import]

You shouldn’t need to put localGroup:removeSelf() in localGroup:clean() since director is going to remove that group itself. The types of things you need to put in there are:

removing event listeners
canceling timers
removing display objects that are not in localGroup.
any game logic that needs to happen when the level closes.

[import]uid: 19626 topic_id: 19491 reply_id: 75897[/import]

@robmiracle thanks for the help also and suggestions. Also if you don’t mind to look at one of my forums that this

I’m wondering what is the best way to have platforms move

[import]uid: 17058 topic_id: 19491 reply_id: 75903[/import]

I’m not that good at platformers. Not sure how much help I can be. Look up some of the “Camera” items in the Community source. (Not camera as taking pictures, but camera as in the view the player has to the scene)
[import]uid: 19626 topic_id: 19491 reply_id: 75907[/import]

@robmiracle the forum I’m saying is I have a 2 moving platforms that are not physics. When you see the platform are moving.

If you see in the forum I posted a plug and play code that shows you what I mean.

But If you can’t help I thank you that at least you tried [import]uid: 17058 topic_id: 19491 reply_id: 75912[/import]