How to "grow" a body

I have a static object that I want to “Grow” each time it is hit. I have tried destroying it in the onCollision event and recreating it, but the physics body seems to still have it lying around and the simulator dies with an assertion error when I try to re-add the body with the new size.

Assertion failed: (IsLocked() == false), function CreateBody, file /Users/ansca/.hudson/jobs/Pong-DMG/workspace/platform/mac/…/…/external/Box2D_v2.1.2/Box2D/Box2D/Dynamics/b2World.cpp, line 84.
/Users/bmccabe2003/Desktop/Corona Game Edition 2010.109/Corona Terminal: line 9: 2024 Abort trap “$path/Corona Simulator.app/Contents/MacOS/Corona Simulator” $*
Is there a simpler way to do this that I am missing?
[import]uid: 11767 topic_id: 4167 reply_id: 304167[/import]

have a variable called _needToCreateBallWithRadius , in your collision set this to the new value you want and then call removeSelf on your original.

in your enterFrame routine put in a condition that checks if a new ball is needed

[lua]local ball = createBallWithRadius(INITIAL_RADIUS)

function onEnterFrame(e)
if(_needToCreateBallWithRadius ~= nil) then
ball = createBallWithRadius(_needToCreateBallWithRadius)
_needToCreateBallWithRadius = nil


end
end[/lua]

box2d doesnt let you create/destroy objects within the current physics world “step”, so the way corona events are structured, enterFrame is the safe place to do it

note: I haven’t tried this, but I don’t know any other way you’d really do it. [import]uid: 6645 topic_id: 4167 reply_id: 12954[/import]

Thanks that works, now I have a sticky ball issue. But there is thread on that. [import]uid: 11767 topic_id: 4167 reply_id: 12963[/import]

ignoring the sticky ball issue. does the physics look like the ball had disappeared (physically rather than visually…so other objects move inward to take its space) and then reappeared (so other objects get pushed back out by the new body), or does it just look like its grown? i guess since it all happens in one frame (or 2) there wouldnt be much difference anyway? [import]uid: 6645 topic_id: 4167 reply_id: 12965[/import]