Re: Fullscreen bug
Posted: Sat Jul 05, 2014 7:39 am
Oh wow. I didn't even know :renderTo() existed. That's a pretty convenient shortcut.
Anyway, the next step is centering the image. T-bone's method above does look like it takes that into account. Here's what you're doing:
When you have a window that's wider than the drawing area, you'll want to center it by figuring out the proper offsets for the top and left. Most of the time, one of these is going to be 0. Usually the top. So we'll concentrate on figuring out the left offset. The formula is simple:
left offset = (window width - (draw width * draw scale)) / 2
Where window width is obvious, draw width is the pixel amount of what you're drawing, in your case 512 and draw scale is the scale value we calculated before. You then use love.graphics.translate(left offset, top offset) inside the love.graphics.push() stuff we added before. To calculate the top offset, you just replace widths with heights. Simple as pie.
If you are using the canvas, then instead of translating it you can just draw the canvas as an image directly to those coordinates at that scale. But either way will work.
To make things easier, store the draw widths and heights as global variables you can use anywhere you need to.
Now here's the tricky part. If you're not using the canvas method, you will probably want to use setScissor to crop out stuff being drawn off to the sides. That's simple, but it won't be affected by pushing and popping so we'll just need to do some simple math to figure out where to scissor. Using the offsets we got above...
love.graphics.setScissor(left offset, top offset, draw width * draw scale, draw height * draw scale)
Put that before your drawing code, but after all coordinates for drawing are calculated. And then after your drawing code, make sure to reset the Scissor by simply calling an empty setScissor function without any coordinates. What the Scissor does is creates a mask where anything drawn will be trimmed. Very useful indeed.
I will try to create a sample main.lua that you can use for reference soon. For now this information should help.
Anyway, the next step is centering the image. T-bone's method above does look like it takes that into account. Here's what you're doing:
When you have a window that's wider than the drawing area, you'll want to center it by figuring out the proper offsets for the top and left. Most of the time, one of these is going to be 0. Usually the top. So we'll concentrate on figuring out the left offset. The formula is simple:
left offset = (window width - (draw width * draw scale)) / 2
Where window width is obvious, draw width is the pixel amount of what you're drawing, in your case 512 and draw scale is the scale value we calculated before. You then use love.graphics.translate(left offset, top offset) inside the love.graphics.push() stuff we added before. To calculate the top offset, you just replace widths with heights. Simple as pie.
If you are using the canvas, then instead of translating it you can just draw the canvas as an image directly to those coordinates at that scale. But either way will work.
To make things easier, store the draw widths and heights as global variables you can use anywhere you need to.
Now here's the tricky part. If you're not using the canvas method, you will probably want to use setScissor to crop out stuff being drawn off to the sides. That's simple, but it won't be affected by pushing and popping so we'll just need to do some simple math to figure out where to scissor. Using the offsets we got above...
love.graphics.setScissor(left offset, top offset, draw width * draw scale, draw height * draw scale)
Put that before your drawing code, but after all coordinates for drawing are calculated. And then after your drawing code, make sure to reset the Scissor by simply calling an empty setScissor function without any coordinates. What the Scissor does is creates a mask where anything drawn will be trimmed. Very useful indeed.
I will try to create a sample main.lua that you can use for reference soon. For now this information should help.