Page 1 of 1

canvas and love.graphics.translate not functioning properly?

Posted: Tue Jul 28, 2015 5:35 pm
by immakinggames
In love.draw()

Code: Select all

love.graphics.push()
love.graphics.setCanvas(canvas)

love.graphics.translate(10, 10)

randomCanvas = love.graphics.newCanvas()
love.graphics.setCanvas(randomCanvas)
    love.graphics.draw(coolImage)
love.graphics.setCanvas(canvas)

love.graphics.draw(randomCanvas)
love.graphics.draw(coolImage)

love.graphics.setCanvas()
love.graphics.pop()
love.graphics.draw(canvas)
why is it such that drawing randomCanvas doesn't translate? Only drawing the image directly translates things, and that seems really weird.

Re: canvas and love.graphics.translate not functioning prope

Posted: Tue Jul 28, 2015 9:03 pm
by DekuJuice
First off, you should not be calling love.graphics.newCanvas() from love.draw, just call it once and store it somewhere so you can reuse it later.

I'm not completely sure that I understand your issue, but from what I see:
immakinggames wrote:

Code: Select all

love.graphics.push()
love.graphics.setCanvas(canvas)

love.graphics.translate(10, 10)

randomCanvas = love.graphics.newCanvas()
love.graphics.setCanvas(randomCanvas)
    love.graphics.draw(coolImage) --Since the translation is in effect, the image is being drawn at 10,10
love.graphics.setCanvas(canvas)

love.graphics.draw(randomCanvas) --The translation is still in effect, meaning the canvas itself is drawn at 10,10, and the image drawn onto it is now at 20,20
love.graphics.draw(coolImage) --Draws the image at 10,10

love.graphics.setCanvas()
love.graphics.pop()
love.graphics.draw(canvas)
When you're drawing to randomCanvas, the image is being translated twice, and when you're drawing it directly, it's only being translated once.