Hello ,
i have problems with how to remove Display Objects :
every second i create a new ball ( newBall() ) and add it to the balls group . when the ball hits the sensor (borderBottom) , i want to delete that ball but instead it quits the whole program .
Can somebody help me here and tell me what i do wrong ? Thank you very much .
koji
local balls = display.newGroup()
local ballsCollisionFilter = { categoryBits = 2, maskBits = 3 }
local ballsBody = { density=0.9, friction=0.4, bounce=0.3, filter=ballsCollisionFilter }
function newBall()
local ball = display.newImage("ball.png")
ball.x = 300
ball.y = -96
physics.addBody( ball , ballsBody )
ball:addEventListener( "touch", startDrag )
balls:insert(ball)
end
local createBall = timer.performWithDelay( 1000, newBall, 0 )
-- SENSOR
local function touch( self, event )
event.other.parent:remove(event.other) --remove from group (balls)
-- !!! HERE IS THE PROBLEM : WHOLE PROGRAMM QUITS (Process completed) !!!
print(balls.numChildren)
end
local borderBottom = display.newRect( 0, display.contentHeight - 100, display.contentWidth, 100 )
physics.addBody( borderBottom, {isSensor=true, bodyType="static"} )
borderBottom.collision = touch
borderBottom:addEventListener( "collision", borderBottom )
[import]uid: 7165 topic_id: 1452 reply_id: 301452[/import]