feat(scene/world): add background color support
This commit is contained in:
parent
2116b83274
commit
6a4d90149f
1 changed files with 24 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue