But I don't update the canvas layout every draw update.
I create a 'static' canvas, and update the layout in it, only when needed using the redraw variable.
Is that still not good enough ?
I thought that I can make the simple gui on top of the game using multiple canvases like this.
And that the thing that that I did draw on it is saved in memory or something.
Or to put it into other words:
- create a canvas
- draw something at the canvas (heavy part)
- save it in memory (like a jpg)
- draw the 'jpg' on screen (and don't do the heavy part, only when needed)
But if I read you text, creating a canvas once, and use it like this is not oke?
The cpu and memory are super low with the 'fix' at the moment.
(it is using alpha mode, because it is a gui inside the game, with a little alpha).
I'm hoping that you say: that saving the result to a canvas, and using it later (like I do below) is possible.
Code: Select all
function drawCanvas(index)
if redraw[index] == false then
return
end
-- create the drawing for this canvas (once)
love.graphics.clear()
love.graphics.setBlendMode("alpha", "alphamultiply")
love.graphics.setColor(1, 0, 0)
love.graphics.rectangle("fill", 20, 20, 100, 100)
love.graphics.draw(texts[index], index * 10, index * 10)
---
redraw[index] = false -- the next loop will call the return
end
function love.draw()
love.graphics.print("FPS: " .. tostring(love.timer.getFPS()), 10, 10)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setBlendMode("alpha", "premultiplied")
for _, canvas in pairs(canvas) do
love.graphics.draw(canvas)
end
love.graphics.setBlendMode("alpha", "alphamultiply")
end