canvas and love.graphics.translate not functioning properly?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
immakinggames
Prole
Posts: 22
Joined: Sat Jun 01, 2013 4:40 am

canvas and love.graphics.translate not functioning properly?

Post 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.
User avatar
DekuJuice
Prole
Posts: 14
Joined: Mon Nov 24, 2014 9:31 pm

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

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests