Started to create canvases that i need and start drawing them. First canvas is working fine, BUT whenever i try to load second canvas, i get a black screen. I don't know why it happens, something is wrong with load not the draw. Also i have put 'love.graphics.clear()', still nothing.
I can't spot the bug, so only thing i can do is ask for help (searched bug 2 days, so what?).
Here is the code:
Code: Select all
local canvases = require("common.canvases")
Cdraw = Class:create("Cdraw")
function Cdraw:new()
love.graphics.draw(canvases.playerPanel,2,(love.graphics.getHeight() - canvases.playerPanel:getHeight()) + 2)
end
function Cdraw:load()
--playerH()
playerP()
end
function playerH()
love.graphics.setCanvas(canvases.playerHealth)
love.graphics.clear()
love.graphics.setBlendMode("alpha","premultiplied")
love.graphics.setColor(255,0,0,156)
love.graphics.rectangle("fill",0,0,canvases.playerHealth:getWidth(),canvases.playerHealth:getHeight())
love.graphics.setColor(255,255,255)
love.graphics.printf({{255,255,255},data.player.hp,{255,255,255},"/",{255,255,255},data.player.maxHp},canvases.playerHealth:getWidth(),"center")
love.graphics.setBlendMode("alpha")
love.graphics.setCanvas()
end
function playerP()
love.graphics.setCanvas(canvases.playerPanel)
love.graphics.setBlendMode("alpha","premultiplied")
love.graphics.setColor(237,245,100)
love.graphics.rectangle("fill",0,0,canvases.playerPanel:getWidth()-5,canvases.playerPanel:getHeight()-5,5,5)
love.graphics.setColor(51,51,0)
love.graphics.setLineWidth(5)
love.graphics.rectangle("line",0,0,canvases.playerPanel:getWidth()-5,canvases.playerPanel:getHeight()-5,5,5)
love.graphics.setLineWidth(2)
--love.graphics.draw(canvases.playerHealth,0,0)
love.graphics.line(canvases.playerPanel:getWidth()/3,0,canvases.playerPanel:getWidth()/3,canvases.playerPanel:getHeight())
love.graphics.setColor(255,255,255)
love.graphics.setBlendMode("alpha")
love.graphics.setCanvas()
end
return Cdraw
Code: Select all
canvases = {
enemyC = love.graphics.newCanvas(400,200),
enemyHealth = love.graphics.newCanvas(300,25),
playerPanel = love.graphics.newCanvas(800,160),
--playerHealth = love.graphics.newCanvas(100,25)
}
canvases.playerHealth = love.graphics.newCanvas(canvases.playerPanel:getWidth()/3,25)
return canvases