diff --git a/examples/short.lua b/examples/short.lua index 3350c90..342fcdf 100644 --- a/examples/short.lua +++ b/examples/short.lua @@ -77,6 +77,12 @@ function love.keypressed(k) if colorAberration == 0.0 then colorAberration = 3.0 end + elseif k == "f" then + lightWorld:remove(lightMouse) + elseif k == "g" then + lightWorld:remove(circleTest) + elseif k == "h" then + lightWorld:remove(rectangleTest) end end diff --git a/lib/init.lua b/lib/init.lua index 1b83f90..863e50c 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -417,4 +417,25 @@ function light_world:getLight(n) return self.lights[n] end +function light_world:remove(to_kill) + if to_kill:is_a(Body) then + for i = 1, #self.body do + if self.body[i] == to_kill then + table.remove(self.body, i) + return true + end + end + elseif to_kill:is_a(Light) then + for i = 1, #self.lights do + if self.lights[i] == to_kill then + table.remove(self.lights, i) + return true + end + end + end + + -- failed to find it + return false +end + return light_world