Re: body:destroy()
Posted: Wed Mar 02, 2011 10:20 am
Oh.... ok. Thanks for that.
Code: Select all
function Unit:predelete()
-- remove shapes from contacts (important for collision callbacks)
for _, shape in pairs(self.shapes) do
shape:setMask(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
end
self.predeleted = true
end
function Unit:delete()
if self.predeleted then
for i, joint in pairs(self.joints) do
joint:destroy()
end
self.joints = {}
for i, shape in pairs(self.shapes) do
shape:destroy()
end
self.shapes = {}
for i, body in pairs(self.bodies) do
body:destroy()
end
self.bodies = {}
self.deleted = true
end
end
function love.update()
if not paused then
-- prepare for removing (remove collision contacts)
for _,unit in ipairs(for_removal) do
unit:predelete()
end
-- update all
for _,unit in ipairs(units) do unit:update() end
world:update(dt)
-- remove
if for_removal ~= {} then
for _,unit in ipairs(for_removal) do
unit:delete()
end
for_removal = {}
end
end
end
Code: Select all
table.insert(for_removal, some_unit)
Code: Select all
int w_Body_destroy(lua_State * L)
{
Proxy * p = (Proxy *)lua_touserdata(L, 1);
p->own = false;
Body * t = (Body *)p->data;
t->release();
return 0;
}
Code: Select all
Body::~Body()
{
world->world->DestroyBody(body);
world->release();
body = 0;
}