The question is rather simple. When should I use a canvas?
From what I can understand, canvases are mostly used for static items such as a background item such as a tree or equivalent to minimize the effort required for love to draw the image every frame therefore increasing performance. But what about things that move such as a parallax background? I assume that for example if I have stacked image objects (drawn in a canvas) on top of each other and I retrieve the canvas image data, only the visible shapes will have their data recorded.
So if I have a parallax background then I can simply draw all the parallax items on a single canvas and then save that as an image or simply draw the canvas?
Which is more efficient(pseudo code) and when is the appropriate cause to use the following:
figure [1]:
Code: Select all
function load()
local image = path.to.image
local image2 = path.to.image2
setCanvas(newCanvas)
draw(image1) -- drawn almost on top of each other so the images overlap a little but not completely
draw(image2)
setCanvas()
imageToDraw = newCanvas:getImageData()
end
function draw()
draw(imageToDraw,variable_x,variable_y)
end
Code: Select all
function load()
local image = path.to.image
local image2 = path.to.image2
setCanvas(newCanvas)
draw(image1) -- drawn almost on top of each other so the images overlap a little but not completely
draw(image2)
setCanvas()
end
function draw()
draw(newCanvas,variable_x,variable_y)
end