[Solved]Canvas and multiple resolutions

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
xCode195
Prole
Posts: 6
Joined: Fri Oct 04, 2013 8:33 pm

[Solved]Canvas and multiple resolutions

Post by xCode195 »

Hello everyone,
I have an issue with using multiple resolutions and canvases.The problem is that when I use canvases everything gets scaled too much,either its too small or too big.I have attached example .love files below.I am using this snippet for resolutions http://love2d.org/forums/viewtopic.php?t=12819

I sense that the solution for this is simple,but for the life of me I can't figure it out :shock: ...

Thanks!
Attachments
noCanvas.love
Not using Canvases
(2 KiB) Downloaded 217 times
Canvas.love
When using canvases
(1.99 KiB) Downloaded 224 times
Last edited by xCode195 on Wed Oct 09, 2013 4:10 pm, edited 1 time in total.
xCode195
Prole
Posts: 6
Joined: Fri Oct 04, 2013 8:33 pm

Re: Canvas and multiple resolutions

Post by xCode195 »

Sorry for bumping but i could really use some input on this before I go further into development and this becomes unfixable :oops: .
Thanks again!
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Canvas and multiple resolutions

Post by raidho36 »

Try swapping around screen and surface dimensions when passing to the ratio computing function in the beginning.
xCode195
Prole
Posts: 6
Joined: Fri Oct 04, 2013 8:33 pm

Re: Canvas and multiple resolutions

Post by xCode195 »

raidho36 wrote:Try swapping around screen and surface dimensions when passing to the ratio computing function in the beginning.
Thanks for responding but,
if you meant these values:

Code: Select all

gw,gh = 1366,768
sw,sh = 800,600
Then it didn't help,also these values must stay that way because gw,gh are values that the game was originally meant to be run on and sw,sh are values of the user set resolution.That means that everything should be at the same place independent of resolution(with black bars on the bottom and top if needed).
Everything works fine(e.g. everything is in it's place independent of resolution) until I start using canvases,even if i don't do anything with the canvas other than draw that same image on it and then draw the canvas itself...
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Canvas and multiple resolutions

Post by raidho36 »

Oh, I see.

Apparently, the "library" applies some kind of global transformation. When you draw without a canvases it works as expected. When draw onto canvas, it would draw everything scaled, as with no canvases, predictably. However, you might intent no scaling for drawing onto canvas, but this will happen anyway unless you manually disable that. And this seems to be your problem.
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Canvas and multiple resolutions

Post by Germanunkol »

I think the reason it's not working as you expect is this:
When you draw onto the canvas, the lg.scale(xscale,yscale) in res.lua (line 58) is active, plus your own scale function. Then, when you draw the canvas, YOUR scale function is inactive, but the res.lua's scale function is still active. This means that when using a canvas, the stuff you draw gets scaled by the res.lua's scaling function twice, plus once by your own scaling function. Instead, each of the scaling functions should only scale it once, which can be achieved like so:

Move the canvas drawing stuff into function love.draw(), before calling res.render:

Code: Select all

function love.draw()
	love.graphics.push()
	love.graphics.setCanvas(canvas)
	love.graphics.scale(5,3)
	love.graphics.draw(image,0,0)
	love.graphics.setCanvas()
	love.graphics.pop()

	res.render(draw)
end
Then, in the draw() function, only call the rendering of the canvas. This way, the stuff you draw doesn't get scaled twice by the res library:

Code: Select all

function draw()
	love.graphics.draw(canvas)
end
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
xCode195
Prole
Posts: 6
Joined: Fri Oct 04, 2013 8:33 pm

Re: Canvas and multiple resolutions

Post by xCode195 »

Germanunkol wrote:-snip-
I LÖVE you man :awesome:
That worked,thank you so much. :cool:
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: [Solved]Canvas and multiple resolutions

Post by Germanunkol »

Glad I could help :)

Kudos goes to Micha though, he taught me how to do it...
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Post Reply

Who is online

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