Code: Select all
-- Delete the object from the map's object list.
map.objects[powObject.id] = nil
-- Delete the object from the layer in the map it is in.
local newObjects = {}
for i, obj in ipairs(powObject.layer.objects) do
if obj ~= powObject then
table.insert(newObjects, obj)
end
end
powObject.layer.objects = newObjects
-- Stop drawing the object.
map:setObjectSpriteBatches(powObject.layer)
Code: Select all
function Map:offset(dx, dy)
self.offsetx = self.offsetx + dx
self.offsety = self.offsety + dy
for _, layer in pairs(self.layers) do
layer.x = layer.x + dx
layer.y = layer.y + dy
end
end
Code: Select all
local body = map.box2d_collision.body
body.setPosition(body.getX() + dx, body.getY() + dy)
More importantly, the map refuses to draw if it moves too far. I'm guessing there's some kind of automatic culling going on. What's the recommended way to deal with this? Am I barking up the wrong tree entirely?