Hi all. Atilim, I put this "local function onMouseDown(event) for i=1,stage:getNumChildren() do local sprite = stage:getChildAt(i) local body = sprite.body if sprite:hitTestPoint(event.x, event.y) then stage:removeChild(sprite) world:destroyBody(body) break end end end
to Sleeping Bodies as you said. It doesn't work and shows the following message: "main.lua:90: bad argument #1 to 'destroyBody' (b2Body expected, got nil) stack traceback: main.lua:90: in function "
What could be wrong here? I stuck with the same think in my project. Thanks.
@paulseau it seems not all stage elements has bodies, so you would also need to check for body, as
localfunction onMouseDown(event)for i=1,stage:getNumChildren()dolocal sprite = stage:getChildAt(i)local body = sprite.body
if sprite:hitTestPoint(event.x, event.y)and body then
stage:removeChild(sprite)
world:destroyBody(body)breakendendend
stage:addEventListener(Event.MOUSE_DOWN, onMouseDown)
Comments
You need:
1. destroy body with b2.World:destroyBody and
2. remove the sprite from stage with Sprite:removeChild
Dislikes: Yan
then in onTouchesBegin function (fired only when you touch the screen of you device)
remove the bodyobject and the relative sprite...
hope it helps.
Ciao Gianluca.
Likes: Karriz
www.tntengine.com
because"Event.TOUCHES_BEGIN" work only on device not in the pc... ;;)
ciao ciao
Gianluca.
www.tntengine.com
"local function onMouseDown(event)
for i=1,stage:getNumChildren() do
local sprite = stage:getChildAt(i)
local body = sprite.body
if sprite:hitTestPoint(event.x, event.y) then
stage:removeChild(sprite)
world:destroyBody(body)
break
end
end
end
stage:addEventListener(Event.MOUSE_DOWN, onMouseDown)"
to Sleeping Bodies as you said. It doesn't work and shows the following message:
"main.lua:90: bad argument #1 to 'destroyBody' (b2Body expected, got nil)
stack traceback: main.lua:90: in function
What could be wrong here? I stuck with the same think in my project.
Thanks.