Page 1 of 1

Scaling for 16:9 resolutions

Posted: Wed Mar 11, 2020 9:02 am
by knuxyl
I'm making a game that I want to always render in 16:9. I will have the window settings be controllable in the game so no maximize/resize buttons on the window itself. I want the game to fit on all screens, but have black borders on different aspect ratios. I also want to be able to scale the game properly. I was going to use percentages of the screen but there's too many fractions involved which can cause graphical problems in other resolutions.

Anways, I'm using a canvas. I need it to always be 16:9 and be able to scale. I've been working on and off on this for years and I used to just use the scale argument but it makes the code clunky but it's looking like thats the best option. I have no idea how to go about the 16:9 resolutions though. Any ideas? I will be porting this game to all platforms, Android/IOS/Mac/Windows and I'm using Linux.

Re: Scaling for 16:9 resolutions

Posted: Wed Mar 11, 2020 10:25 am
by Astorek86
There are some Libs out there which provides exactly what you want. Two very good Libs are

Re: Scaling for 16:9 resolutions

Posted: Wed Mar 11, 2020 8:27 pm
by zorg
Or if you want the explanation bit, there's only ever 3 cases you need to care about with the expectation of you always wanting your canvas to be 16:9 aspect ratio with fullscreen:
- the screen is already 16:9 -> nothing to do
- the screen is vertically larger -> you need to letterbox the top and bottom, meaning you'll offset your rendering vertically by (screenheight -closest_smaller_16:9_height) / 2
- the screen is horizontally larger -> you need to pillarbox the sides, meaning you'll offset your rendering horizontally by (screenwidth - closest_smaller_16:9_width) / 2