I am going to reuse a scene to do multiple levels (I will not leave the scene) but wanted to “clean up” my code before starting the next level. But, since I am a newbie, I do not know how to cleanup my code.
I am doing the following…
local function removeObject() display.remove(obj.text) display.remove(obj) obj = nil end timer.performWithDelay(50, removeObject, 1)
I was told I had to remove timers. is that true? Why? Isn’t it the same as a function? If yes, then I need to know how to remove this timer.
levelText = display.newText("Level - "..level.." Begin",0,0,native.systemFontBold,25); sceneGroup:insert(levelText)
plus many other display objects
I could either remove the backgrounds and readd them or put in logic that says - if already been here then don’t add again. Which is best? if I should remove backgrounds then how?
local bg = display.newImageRect("images/bg.png",\_W,\_H) sceneGroup:insert(bg)
What about physics items? Do those need to be deleted too?
physics.addBody(floor, "static") local myListener = function( event ) for i=1, 10 do circles[i].text.x=circles[i].x circles[i].text.y=circles[i].y end end Runtime:addEventListener( "enterFrame", myListener )
Also how do I best clear out that table for circles?
c:addEventListener("touch", touchCircle) -- to make it touchable c:addEventListener("collision", CollisionWithLine) -- to make it check if collided.
Do those need to be cleared as well?
I think that is all. I didn’t add duplicates of things similar. I can figure those out after understanding these.