improvement(boxes): only use one texture for boxes instead of two
This commit is contained in:
parent
afbbf50539
commit
4e366051c4
1 changed files with 24 additions and 23 deletions
|
@ -37,10 +37,8 @@ function Box3D:new(owner, w, h, d)
|
|||
self.shadowSources = {}
|
||||
self.needRedraw = false
|
||||
|
||||
self.texture = {}
|
||||
self:setTopTexture()
|
||||
self:setBottomTexture()
|
||||
self.texture.shadows = love.graphics.newCanvas(self.w, self.h)
|
||||
self:setTexture()
|
||||
self.shadows = love.graphics.newCanvas(self.w, self.h)
|
||||
|
||||
self:register()
|
||||
end
|
||||
|
@ -62,29 +60,33 @@ function Box3D:setSize()
|
|||
self:regenerate()
|
||||
end
|
||||
|
||||
function Box3D:setTopTexture()
|
||||
local canvas = love.graphics.newCanvas(self.w, self.h)
|
||||
function Box3D:setTexture()
|
||||
local canvas = love.graphics.newCanvas(self.w, self.h + self.d)
|
||||
love.graphics.setCanvas( canvas )
|
||||
utils.graphics.resetColor()
|
||||
love.graphics.rectangle("fill", 0, 0, self.w, self.h)
|
||||
|
||||
self:drawTextureContent()
|
||||
|
||||
love.graphics.setCanvas( )
|
||||
local imagedata = canvas:newImageData()
|
||||
self.texture.top = love.graphics.newImage( imagedata )
|
||||
self.texture = love.graphics.newImage( imagedata )
|
||||
imagedata:release()
|
||||
canvas:release()
|
||||
end
|
||||
|
||||
function Box3D:setBottomTexture()
|
||||
local canvas = love.graphics.newCanvas(self.w, self.d)
|
||||
love.graphics.setCanvas( canvas )
|
||||
love.graphics.setColor(0.9, 0.9, 0.9, 1)
|
||||
love.graphics.rectangle("fill", 0, 0, self.w, self.d)
|
||||
function Box3D:drawTextureContent()
|
||||
self:drawTopTexture()
|
||||
self:drawBottomTexture()
|
||||
end
|
||||
|
||||
function Box3D:drawTopTexture()
|
||||
utils.graphics.resetColor()
|
||||
love.graphics.setCanvas( )
|
||||
local imagedata = canvas:newImageData()
|
||||
self.texture.bottom = love.graphics.newImage( imagedata )
|
||||
imagedata:release()
|
||||
canvas:release()
|
||||
love.graphics.rectangle("fill", 0, 0, self.w, self.h)
|
||||
end
|
||||
|
||||
function Box3D:drawBottomTexture()
|
||||
love.graphics.setColor(0.9, 0.9, 0.9, 1)
|
||||
love.graphics.rectangle("fill", 0, self.h, self.w, self.d)
|
||||
end
|
||||
|
||||
function Box3D:setShadowSource(actor, x, y)
|
||||
|
@ -123,7 +125,7 @@ end
|
|||
|
||||
function Box3D:redrawShadowCanvas()
|
||||
if (self.needRedraw) then
|
||||
love.graphics.setCanvas( self.texture.shadows )
|
||||
love.graphics.setCanvas( self.shadows )
|
||||
love.graphics.clear()
|
||||
for i,v in ipairs(self.shadowSources) do
|
||||
v.actor:drawShadow(v.x, v.y)
|
||||
|
@ -141,10 +143,9 @@ function Box3D:draw(x, y, z)
|
|||
love.graphics.rectangle("line", x, (y-z) - (self.d), self.w, self.d + self.h)
|
||||
end
|
||||
utils.graphics.resetColor()
|
||||
love.graphics.draw(self.texture.top, x, (y-z) - (self.d))
|
||||
love.graphics.draw(self.texture.bottom, x, (y-z) - (self.d) + (self.h))
|
||||
if (self.texture.shadows ~= nil) and (#self.shadowSources > 0) then
|
||||
love.graphics.draw(self.texture.shadows, x, (y-z) - (self.d))
|
||||
love.graphics.draw(self.texture, x, (y-z) - (self.d))
|
||||
if (self.shadows ~= nil) and (#self.shadowSources > 0) then
|
||||
love.graphics.draw(self.shadows, x, (y-z) - (self.d))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue