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 )
I can’t get your sample to work exactly as is, but… running the terminal version of Corona Simulator, do you see any output in the console? [import]uid: 54 topic_id: 1452 reply_id: 4060[/import]
Ok, it turns out this is a known problem in Alpha 1 – removing objects doesn’t work. We’re working on a fix. [import]uid: 54 topic_id: 1452 reply_id: 4062[/import]
@Eric wouldn’t it be better to move topics into the right section? I found that people tend to post where they found the last “related” topic in a forum. [import]uid: 6928 topic_id: 1452 reply_id: 4091[/import]
This should be fixed as of Alpha 3 (not yet released), unless some new problem arises in testing.
Calling either object:removeSelf(), or object.parent:remove(object), should then work anytime, anywhere. [import]uid: 3007 topic_id: 1452 reply_id: 4136[/import]
I was try to do new application in which at bottom side one slider is moving and from top of the screen some object are dropped when both are interact at that time object is removed.
Above task are finished.
But I have also implement one more thing in this - device is move from left to right ( means user moving left or right any point from the screen ) .
Is there any methods which is help me for this ?
[import]uid: 11428 topic_id: 1452 reply_id: 12914[/import]
This sounds like a problem happening in another post (http://developer.anscamobile.com/forum/2010/12/03/how-grow-body) which I believe (from similar experience) that the problem is caused by trying to significantly modify a physics object within its own event handler. I also believe this is a bug in the system (sorry, Ansca) but that it can be circumvented by setting a very short timer to complete the operation which is causing the problem. Simply move the removeSelf into the timer listener and fire the timer from within the collision listener.
@evank: Is there any news on whether physics event listeners are causing problems with subsequent body modifications. As I linked above, there are a number of people experiencing this at the moment. Though I’m not sure I follow your description of the ‘removing objects in Alpha 1’ as I can remove objects in my code. Is there a special circumstance in which this happens?
I had the same problem and posted in the bug report forum recently about it. However in my case the problem seems to be only on the simulator. On the device it works fine. [import]uid: 10835 topic_id: 1452 reply_id: 13017[/import]