I have some physics objects which I want to remove when my game over function is called. I loop through my data table (refuse) and try to remove them if they exist on the screen. I tried removing the group that they are all in but if an object is touched before and released after the game over my app crashes, presumably because the touch event is unresolved. Here is some code, please help me:
-------------------
function fadeOutDestroy( body )
local body = body
local destroy = function()
body:removeEventListener( "touch" , dragRefuse )
body:removeSelf()
body = nil
end
transition.to( body, { time=500, delay=500, alpha=0, onComplete=destroy } )
end
-------------------
--\> loop through the refuse data table and remove objects from screen
for i=1, #refuse do
if refuse[i].object then
local body = refuse[i].object
print ( body.name )
fadeOutDestroy( body )
end
end
-------------------
…But the corona terminal returns a runtime error saying: ‘attempt to call method ‘removeSelf’ (a nil value)’ [import]uid: 11712 topic_id: 10929 reply_id: 310929[/import]