Page 1 of 1

graphics.clear clears screen instead of canvas

Posted: Sat May 30, 2015 11:49 am
by ardera
There is not much code to reproduce this, you don't need to download the .love file.

It's easy:

Code: Select all

function love.load()
  mycanvas = love.graphics.newCanvas(300, 300)
end
function love.draw()
  love.graphics.setCanvas(mycanvas)
  love.graphics.setColor(255, 255, 255, 255)
  love.graphics.setBackgroundColor(0, 0, 255, 0)
  love.graphics.clear()
  love.graphics.setCanvas()
end
Normally, you should just see a black screen, because the canvas is never drawn to the screen.
But instead, at least setBackgroundColor and clear are targetting the screen instead of the canvas, so you see a blue screen.

I am using an unmodified version of love version 0.9.2

Re: graphics.clear clears screen instead of canvas

Posted: Sat May 30, 2015 1:34 pm
by Robin
You can use [wiki]Canvas:clear[/wiki] instead.

Re: graphics.clear clears screen instead of canvas

Posted: Sat May 30, 2015 1:43 pm
by slime
love.graphics.clear is called automatically before love.draw, in the default [wiki]love.run[/wiki] – and your call to love.graphics.setBackgroundColor affects that.

Re: graphics.clear clears screen instead of canvas

Posted: Sat May 30, 2015 6:14 pm
by Robin

Code: Select all

function love.load()
	mycanvas = love.graphics.newCanvas(300, 300)
end
function love.draw()
    love.graphics.print("If you can see this, slime is right")
	love.graphics.setCanvas(mycanvas)
	love.graphics.setColor(255, 255, 255, 255)
	love.graphics.setBackgroundColor(0, 0, 255, 0)
	love.graphics.clear()
	love.graphics.setCanvas()
end
(And I was wrong.)