Page 1 of 1

Canvas Help [SOLVED]

Posted: Sat Jul 19, 2014 5:03 pm
by Lolocks
Some I'm starting to make a new game and I've come across a bug that should really be repaired.

Short background story: I'm using the canvas thingy to make a startup menu with different pages.

Anyways, for some reason, when I set the canvas after converting into one, the canvas is blank. I asked a friend about this and he said he got that problem too. The only way he got around it was removing some code from the canvas. Problem is, I don't want to remove some code and make everything unorganized and stuff. Is there a way to get around this bug?

Expected: The canvas is drawn exactly how it was coded
Problem: The canvas appears blank when drawn

Code:

Code: Select all

function love.load()
	--main variables
	flux = require "flux" --flux.to(obj, time, { x = num, y = num})
	Quickie = require "Quickie"
	TitleFont = love.graphics.newFont("/fonts/FaceYourFears.ttf", 45)
	--Canvas
	MainMenuCanvas = love.graphics.newCanvas()
	HowToPlayCanvas = love.graphics.newCanvas()
	CreditsCanvas = love.graphics.newCanvas()
	--MainMenu Canvas
	love.graphics.setCanvas(MainMenuCanvas)
		MainMenuCanvas:clear()
		love.graphics.setFont(TitleFont)
		love.graphics.setColor(255, 0, 0)
		love.graphics.print(_G.GameTitle, (TitleFont:getWidth(_G.GameTitle)/2), 10)
end

function love.update(dt)
	--
end

function love.draw()
	love.graphics.draw(MainMenuCanvas)
end
EDIT: Added .love file

Re: Canvas Help

Posted: Sat Jul 19, 2014 5:23 pm
by MadByte
When setting a canvas with love.graphics.setCanvas(canvas) you need to call the function a second time to "finish" your canvas object.
Therefor you simply have to put love.graphics.setCanvas() without an argument behind your canvas code.

Code: Select all

   --MainMenu Canvas
   love.graphics.setCanvas(MainMenuCanvas)
   MainMenuCanvas:clear()
   love.graphics.setFont(TitleFont)
   love.graphics.setColor(255, 0, 0)
   love.graphics.print(_G.GameTitle, (TitleFont:getWidth(_G.GameTitle)/2), 10)
   love.graphics.setCanvas() -- new line

Re: Canvas Help

Posted: Sat Jul 19, 2014 5:30 pm
by Lolocks
MadByte wrote:When setting a canvas with love.graphics.setCanvas(canvas) you need to call the function a second time to "finish" your canvas object.
Therefor you simply have to put love.graphics.setCanvas() without an argument behind your canvas code.

Code: Select all

   --MainMenu Canvas
   love.graphics.setCanvas(MainMenuCanvas)
   MainMenuCanvas:clear()
   love.graphics.setFont(TitleFont)
   love.graphics.setColor(255, 0, 0)
   love.graphics.print(_G.GameTitle, (TitleFont:getWidth(_G.GameTitle)/2), 10)
   love.graphics.setCanvas() -- new line
Thanks!