feat(boxes): add a way to make basic boxes invisible

This commit is contained in:
Kazhnuz 2019-07-20 17:10:40 +02:00
parent 3e26d9a769
commit 7d65359230

View file

@ -23,7 +23,7 @@
local Box3D = Object:extend() local Box3D = Object:extend()
function Box3D:new(owner, w, h, d) function Box3D:new(owner, w, h, d, isVisible)
self.owner = owner self.owner = owner
self.world = owner.world self.world = owner.world
self.cameras = self.world.cameras self.cameras = self.world.cameras
@ -37,7 +37,12 @@ function Box3D:new(owner, w, h, d)
self.shadowSources = {} self.shadowSources = {}
self.needRedraw = false self.needRedraw = false
self:setTexture() self.isVisible = isVisible or true
if (self.isVisible) then
self:setTexture()
end
self.shadows = love.graphics.newCanvas(self.w, self.h) self.shadows = love.graphics.newCanvas(self.w, self.h)
self:register() self:register()
@ -138,12 +143,15 @@ function Box3D:redrawShadowCanvas()
end end
function Box3D:draw(x, y, z) function Box3D:draw(x, y, z)
love.graphics.setColor(0, 0, 0, 1) if (self.isVisible) then
if (self.haveLine) then love.graphics.setColor(0, 0, 0, 1)
love.graphics.rectangle("line", x, (y-z) - (self.d), self.w, self.d + self.h) if (self.haveLine) then
love.graphics.rectangle("line", x, (y-z) - (self.d), self.w, self.d + self.h)
end
utils.graphics.resetColor()
love.graphics.draw(self.texture, x, (y-z) - (self.d))
end end
utils.graphics.resetColor()
love.graphics.draw(self.texture, x, (y-z) - (self.d))
if (self.shadows ~= nil) and (#self.shadowSources > 0) then if (self.shadows ~= nil) and (#self.shadowSources > 0) then
love.graphics.draw(self.shadows, x, (y-z) - (self.d)) love.graphics.draw(self.shadows, x, (y-z) - (self.d))
end end