Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question I have three related questions about cameras and device resolutions...

Discussion in '2D' started by IIBearWithII, Aug 27, 2023.

  1. IIBearWithII

    IIBearWithII

    Joined:
    Feb 15, 2023
    Posts:
    87
    1) Say I'm designing a game for a device resolution of 2960 x 1440. And I have a background image centered with the camera's orthographic view. The camera's size is set to half of the height of the screen, divided by 100 pixels per unit. So the camera size would be 14.8. From what I understand, that would make the background image pixel perfect. Is that correct?

    2) If I also want to have the game available on a device that has a resolution of 2560 x 1312, should I create a script that will analyze the size of the device running the game and lower the size of the camera to 12.8 when necessary? (I understand this will cut off some of the image from view.)

    3) If I don't create that script to analyze the size of the device, if the device running the game is 2560 x 1312, would the background image no longer be pixel perfect? (More pixels would need to be represented than there would be space for, so I don't see how it could be pixel perfect...)
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Here are some notes on UI Anchoring, Scaling, CanvasScaler, etc:

    https://forum.unity.com/threads/inc...size-between-two-people.1130146/#post-7261747

    https://forum.unity.com/threads/game-ui-button-size-problem.1142650/#post-7337383

    Usually you need to choose a suitable ScaleMode and MatchMode in the Canvas Scaler and stick with it 100%. Generally if you change those settings you will often need to redo your UI entirely.

    I also use this
    CanvasScalerOrientationDriver
    utility to make sharing UI for Landscape / Portrait easier. Read what it does carefully.

    https://gist.github.com/kurtdekker/8802b1b6c708637398f8c9167641efd3
     
    IIBearWithII likes this.
  3. IIBearWithII

    IIBearWithII

    Joined:
    Feb 15, 2023
    Posts:
    87
    My fault, I didn't specify before. But, do you have any advice for me on this topic, but more specifically to non-canvas and non-UI?
     
  4. sildeflask

    sildeflask

    Joined:
    Aug 16, 2023
    Posts:
    142
    use this formula for the camera

    Code (CSharp):
    1. ((Screen.currentResolution.height) / (scale * PPU)) * 0.5f
    if your background image ceases to be the same size of the screen resolution it will also cease to display pixel perfect, unless you create perfect conditions
     
    IIBearWithII likes this.
  5. IIBearWithII

    IIBearWithII

    Joined:
    Feb 15, 2023
    Posts:
    87
    Thanks!