Okay, I am looking for a command that will delete all of these physics bodies that have been automatically spawned, and I want them to be deleted when the scene changes or exits. I have searched on the internet for this type of thing, but it seems nothing like this exists (either that or I’m blind :P). I’m new at coding, so try to keep your answers as simple as possible.
The code:
[lua]
–locals
function onCobbleTouch(self, event)
if(event.phase == “began”) then
timer.performWithDelay(1, function() self:removeSelf() end )
end
return true
end
local infinite = 1000000000000000000000000000000000000000000000000000
–spawning command
function spawnCobble( event )
local cobbleBlock = display.newImageRect( “cobblestone.png”, 50, 50 )
cobbleBlock.x = math.random( 320 )
cobbleBlock.y = -100
cobbleBlock.rotation = math.random( 360 )
physics.addBody( cobbleBlock, { density=13, friction= 0.75, bounce= 0.1 } )
cobbleBlock.touch = onCobbleTouch
cobbleBlock:addEventListener(“touch”, cobbleBlock)
group:insert( cobbleBlock )
return cobbleBlock
end
blockTimer = timer.performWithDelay( 300, spawnCobble, infinite)
[/lua]
I want all of these physics bodies (cobbleBlock) that have been automatically spawned (in the timer.performWithDelay command) to be deleted when the scene changes or exits. Any help appreciated.
P.S. This is my first post on this forum so if I stuffed anything up please let me know.