Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Screen Resolution / Aspect Ratio Best Practices for 2D Games

Discussion in '2D' started by VoodooDetective, Apr 16, 2020.

  1. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    239
    Here is my understanding of the options available to us:

    Aspect Ratio
    1. Enforce a specific aspect ratio
      1. Black bars around the screen when the actual screen aspect ratio isn't available.
    2. Enforce a set of aspect ratios from a list (allow player to choose from list)
      1. Black bars around the screen when the actual screen aspect ratio isn't available.
    3. Allow all aspect ratios
      1. Make sure to add a fade to black around all backgrounds
      2. Make sure camera bounds are greater than any possible aspect ratio
    Screen Resolution
    1. Give the option to change resolution
    2. Don't give the option to change resolution
    Different Devices
    1. Have a build for each target device type (phone, computer, etc.). For phones, you might use lower quality assets based on the assumption that you have lower power devices, and less screen real estate.

    Can experts chime in to let me know if I missed anything, and maybe tell me what the best practices are given these options?
     
    Rany_AN likes this.
  2. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,262
    These questions are usually specific to each game.

    Games like Issac, backgrounds are a specific size. Black bars would be needed to maintain the backgrounds aspect ratio, or restrict changing resolution which forces windowed mode so you don't get stretching. Or make different background sizes for each resolution, which is not feasible to keep the game size down.

    Games like Zelda go by world size so no need to enforce specific resolution or aspect. Camera is restricted to world bounds. Different aspects will see more or less of the screen but isn't really a problem.

    Thinking about mobile, you have to worry about portrait and landscape. Its easy enough to enforce either through the editor.

    One game I'm working on for mobile is landscape only and doesn't worry about a specific screen size. Orthographic size is half vertical so it will always maintain that. I didn't worry about width, I use some math to get the edge of the screen to spawn what ever needed to be spawned.

    Another one is portrait only that enforces the camera to be a specific width no matter what the screen size it. The camera gets restricted vertically.
     
    VoodooDetective likes this.
  3. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    239
    Thanks so much for your reply! I did some research on some recent indie 2D games and how they handle different aspect ratios. The resounding choice seems to be fixed aspect ratio with some form of letterboxing/pillarboxing. Take a look at Cuphead/Oxenfree/Celeste/Unavowed/etc. All of them force 16:9.

    The question I have now is what is the most efficient method of doing that. I found two different options.
    1. Using Camera.rect and a background camera to fill in the pillar/letterbox.
    2. Rendering the camera to a RenderTexture, putting that texture in a canvas, and using aspect ratio fitter.
    It seems to me the former should be more efficient, but I actually have no idea. In my examples, I'm guessing Cuphead may have done the latter.

    Just for reference, here's a nice tutorial for method 1:
    http://www.aclockworkberry.com/managing-screen-resolution-and-aspect-ratio-in-unity-3d/

    Here's a vague idea of how to do method 2:
    http://answers.unity.com/answers/1606820/view.html

    With method 1, it seems like you can't use overlay canvases. Not sure the implications there.

    I'm just wondering now which method is more efficient. I should probably post another question.
     
    Last edited: Apr 17, 2020
  4. Edualcz

    Edualcz

    Joined:
    Feb 15, 2020
    Posts:
    9
     
  5. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,262
    1. Is more efficient than 2. Render background camera that is only clearing to black, then render the game with another camera overlaying the background within a given rect set to the aspect ratio desired.

    2. Having to render to render texture, then assign that render texture to a raw image on a canvas then render that image. It still requires 2 cameras with another step of rendering of the raw image. It still needs a background image to have the black bars, so there is even more to render.

    In the end though its probably not all that much of a difference, but for efficiency, the first method requires less. An extra camera and some math to set the rect of the game camera.

    A simple script you can add to the camera, provide an aspect ratio and it does the rest of the work including adding and setting up the second camera at run time.

    http://wiki.unity3d.com/index.php/AspectRatioEnforcer
     
  6. Hemal_Gamedev

    Hemal_Gamedev

    Joined:
    Dec 3, 2021
    Posts:
    2
    what is the correct resolution for unity PC games in portrait mode?
     
  7. angeldevelopment

    angeldevelopment

    Joined:
    Sep 28, 2022
    Posts:
    247
    We just use a reference resolution and when a scene is loaded compare the width of the current screen to that, if the width of the current screen is 20% higher that the reference resolution used during development then all game object are scaled by 20% when the scene is loaded. Any objecting being spawned for mobile should be pooled anyway. This is what we do for 2d portrait, not for 3d obviously.
     
  8. angeldevelopment

    angeldevelopment

    Joined:
    Sep 28, 2022
    Posts:
    247
    16:9