I am trying to remove multiple objects when they fall down . When I try to do this only 1 ball removes itself and the other two stay . How can I remove all when I touch them individually ?
local numberBall = 3 local function spawnBall() for i = 1 , numberBall do Ball = display.newCircle(60, 60, 13) Ball.x = math.random(10, 300); Ball.y = 50; Ball:setFillColor( 0, 5, 0 ) transition.to( Ball, { time=math.random(4000,8000), x=math.random(-10,100) , y=600, onComplete=clearBall } ); physics.addBody( Ball, "dynamic", { density=0.1, bounce=0.1, friction=0.1, radius=0 } ); Ball:applyLinearImpulse(-.05, .05, 0, 0) Ball.touch = touch end end spawnBall()
function Ball.touch( self, event ) --line 55 if ( event.phase == "ended" ) then display.remove(self) end end function scene:show(event) Ball:addEventListener("touch") end function scene:hide(event) Ball:removeEventListener("touch") composer.removeScene( "restart" ) end