Hi,
I've again found something I don't completely understand. During gameplay, I sometimes want to destroy a body and sprite (in a for body,sprite in pairs(actors) do loop) by using:
if (sprite.removeMe) then
world:destroyBody(body)
stage:removeChild(sprite)
actors[body] = nil
end |
and sometimes I will keep the picture/sprite in place and only deactivate the body by using:
if (sprite.removeMyBody) then
body:setActive(false)
sprite.removeMyBody = false
end |
Sometimes I will get an error:
main.lua:190: Body is already destroyed.
Instead of body:setActive(false), destroying the body is also possible but gives me more errors.
Is there a proper way to determine if a body has removed from the actors array?
I tried this but this doesn't seems to work:
for body,sprite in pairs(actors) do
if body ~= nil then
.....
end |
Can't you use the nil test on a body?
Thanks,
Marc
Comments
So I'd say first you would need to check if body should be removed like this:
that body is an object so I can test if it is nil? I can also add an
property, like sprite.body.removed to tell that a body is removed.
Regards,
Marc
I'm usually doing something similar for joints