feat(scene/world): add background color support

This commit is contained in:
Kazhnuz 2024-10-30 19:54:06 +01:00
parent 2116b83274
commit 6a4d90149f

View file

@ -50,6 +50,7 @@ function World:new(datas)
end
self:_initMap(map)
self:_initBackground(self.def.background or {})
self.actors = {}
self.bodies = Bump3D.newWorld(50)
@ -77,6 +78,7 @@ function World:update(dt)
end
function World:draw()
self:_drawBackground()
self.camera:attachView()
self:drawLowerLayers()
self:drawShapes()
@ -310,4 +312,26 @@ function World:drawShapes()
end
end
-- BACKGROUND
-- Default color behind the world
function World:_initBackground(background)
self.background = {r = background.r or 0, g = background.g or 0, b = background.b or 0}
end
function World:_drawBackground()
local r, g, b = love.graphics.getColor()
local background = self.background
if (self.map ~= nil) then
background.r, background.g, background.b = self.map:getBackgroundColor()
end
love.graphics.setColor(background.r, background.g, background.b, 1)
local w, h = core.screen:getDimensions()
love.graphics.rectangle("fill", 0, 0, w, h)
love.graphics.setColor(r, g, b, 1)
end
return World