This is something else then love.graphics.isSupported("multicanvas") that I don't want to use because I don't want to use simultaneously drawing and has less support.
The cool thing about a canvas is, that I can draw everything using 0,0 top left so its more easy to do some things (for me).
1.
Using more than one canvas, will that cost more gpu/cpu/mem ?
2.
But the real question is this, code below, is that the way to do it ?
See the top and bottom canvas like a menu and don't update very often.
The game is in the middle canvas.
Code: Select all
function love.load()
canvasTop = love.graphics.newCanvas(config.screenWidth, 50)
canvasMiddle = love.graphics.newCanvas(config.screenWidth, 550)
canvasBottom = love.graphics.newCanvas(config.screenWidth, 90)
love.graphics.setCanvas(canvasBottom)
love.graphics.setColor(1, 0, 0, 0.5)
love.graphics.rectangle("fill", 0, 0, config.screenWidth, 90)
love.graphics.setCanvas()
end
function love.update(dt)
-- nothing for canvas functions
end
function love.draw()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setCanvas(self.canvasTop)
-- do draw things for canvas Top
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setCanvas(canvasMiddle)
-- do draw things for canvas Middle
-- do draw things for canvas bottom, or is this better in the love.update function
canvasBottom:renderTo(
function()
love.graphics.clear()
-- ^ Now because I use this, I can't do dynamic drawing like the rule below (because it will render over the other text)
-- But now the whole idea about a canvas is 'faster' is away now, but it is still easy to use I think.
love.graphics.print("x: " .. tostring(love.mouse.getX()) .. " y: " .. tostring(love.mouse.getY()), 0, 0)
-- The idea about the canvasBottom is to hold some buttons and indicators, so maybe this is the good way to do it
if newUpdate then
love.graphics.clear()
end
-- and do the things
end
)
-- draw everything
love.graphics.setCanvas()
love.graphics.draw(canvasTop, 0, 0, 0, 1, 1)
love.graphics.draw(canvasMiddle, 0, 50, 0, 1, 1)
love.graphics.draw(canvasBottom, 0, 550, 0, 1, 1)
end