By popular request here it is: how to make a game fill up the screen while
- keeping the same aspect ratio,
- zooming in to fill as much of the screen as will fit, but only integer zoom levels so weird stretch patterns don't appear,
- filling extra space with black bars,
- not wasting VRAM (you import all your graphics at normal size),
- positioning UI elements at the same place on-screen,
- and not blurring the display.
I always assumed it was possible, but nobody seems to have done it yet. It has been possible in Construct Classic for a while, but I'll admit - it was a little complicated. You have to use some tricks.
Here's the file: http://dl.dropbox.com/u/15217362/fullscreen.cap (r1.2)
How it's done:
We shouldn't stretch the window surface, or DirectX will probably linear filter it, blurring the pixels. So Project Propertes -> Resizing is set to "show more window content" - making the window bigger shows more pixels, without automatically sizing anything. We do the zooming ourselves.
Project Properties -> Sampling is "Point", so nothing linear filters and blurs.
Layout properties -> Unbounded scrolling enabled, so we don't hit scrolling limitations to do with zoom.
There are three layers: main, UI and one for the black bars. These are all ordinary scrolling layers. This means we don't have to deal with objects going offscreen when the zoom changes, the objects are manually positioned.
Most of the rest is Good Old Maths:
- a global zoom is set to the largest integer size that will fit inside the screen bounds. So for example if 2x will fit, it will use that, or 3x if it fits, or 1x if the window is small.
- some maths positions the black bars on a scrolling layer in such a way they obscure everything that you shouldn't see.
- the UI layer is also a scrolling layer, but a UIOrigin sprite is positioned at the top left of the viewable area, so you can position your UI elements from there.
- F and W switch between fullscreen and windowed.
Hope that helps. Back to Construct 2!