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 ...
Thanks!
[Solved]Canvas and multiple resolutions
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[Solved]Canvas and multiple resolutions
- 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.
Re: Canvas and multiple resolutions
Sorry for bumping but i could really use some input on this before I go further into development and this becomes unfixable .
Thanks again!
Thanks again!
Re: Canvas and multiple resolutions
Try swapping around screen and surface dimensions when passing to the ratio computing function in the beginning.
Re: Canvas and multiple resolutions
Thanks for responding but,raidho36 wrote:Try swapping around screen and surface dimensions when passing to the ratio computing function in the beginning.
if you meant these values:
Code: Select all
gw,gh = 1366,768
sw,sh = 800,600
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...
Re: Canvas and multiple resolutions
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.
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.
-
- Party member
- Posts: 712
- Joined: Fri Jun 22, 2012 4:54 pm
- Contact:
Re: Canvas and multiple resolutions
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:
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:
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
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
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Re: Canvas and multiple resolutions
I LÖVE you manGermanunkol wrote:-snip-
That worked,thank you so much.
-
- Party member
- Posts: 712
- Joined: Fri Jun 22, 2012 4:54 pm
- Contact:
Re: [Solved]Canvas and multiple resolutions
Glad I could help
Kudos goes to Micha though, he taught me how to do it...
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
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 13 guests