- Home /
Centering aspect ratios in fullscreen
Hello
The game I am making uses a 1:1 aspect ratio. This works fine, however, when I go into fullscreen, the entire screen is pushed all the way to the left as you can see in the picture. This is just annoying to look at and I'd much rather have it in the center.
However, I would like to retain the aspect ratio as there are some parts of the game that also need to work with the square screen. Is there a way to just center the screen, so that the picture would look the same, except the game is in the center of the screen? If not or if it is really hard and innefficient, I'll probably just make the screen fit whatever aspect ratio people play with and then add black bars on the GUI.
Answer by Bunny83 · Sep 07, 2020 at 08:25 AM
Well, it's completely unclear what we're actually looking at and how the graphics are produced at the moment. Is this just UI? Do you actually use a camera to render this? How did you actually ensure this aspect ratio? When you use a camera, you can simply restrict the rendering area to whatever screen region you want. There you can also fix varying aspect ratios. Of course the remaining area would not be rendered at all and could cause visual artifacts, depending on the target platform. So when using a camera to render your game, it's generally better to have two cameras. One that renders / clears the background and one that is restricted to the screen center and actually renders your game content.
If this is actually just UI stuff it gets even more diffuse since there are countless of different ways how things can get arranged on the screen. So without further details on what we're currently looking at this can not really be answered.
Fair enough. I am new to both Unity and asking for help in Unity, so thanks for asking specific questions that could help you help me.
This is rendered by the $$anonymous$$ain Camera object and this is the main view of the game, text at the top left being in the only UI element, which is rendered with a canvas. I have created this aspect ratio, by changing the width and height to 1.5f in the script and then by setting the Camera.aspect to 1/1.
For UI, I used GUI for a special effect in specific parts of the game (that is what all of my references to UI are for in the original comment)
This phrase: "When you use a camera, you can simply restrict the rendering area to whatever screen region you want" is what I believe I've done - there are many more gameobjects outside this view but I restricted the camera to only see a 5*5 grid. $$anonymous$$y confusion comes from not being able to move this camera to the center, so that there would be black background both left and right of the main camera, not just to the right.
After some experimentation, I was able to create this
which achieves the desired effect (in game, the camera now goes across the entire screen, but the black bars are above other elements and so the 5*5 grid is the only thing shown), but this will force me to do some more effort in adjusting some effects that relied on the square being a camera (such as zoo$$anonymous$$g out and a texture that goes across the entire screen). Though this isn't a large problem, I am simply curious about a method that would keep a 1:1 aspect ratio and would simply allow me to move the camera to the center of the screen.
Your answer
Follow this Question
Related Questions
trouble when rendering canvas on android 1 Answer
Why is the camera aspect ratio broken for the game tab? 0 Answers
Ortho camera viewport setup? 3 Answers
RenderTarget in scripts 0 Answers
What is the meaning of 1:1 in unity? 1 Answer