Search Unity

Orthographic Camera Size, Multiple Resolutions, IPhone

Discussion in '2D' started by khan53, May 23, 2015.

  1. khan53

    khan53

    Joined:
    May 16, 2015
    Posts:
    4
    After googling around, I know this question has been asked a million times; but I'm still confused in getting my head around this.

    Focusing on Apple devices (the iPhones), I plan to (half way through) design my art (sprites) for the iPhone 6 and scale to fit between iPhone 5's and iPhone6+...for the iPhone4, I will rescale the art in accordance to its aspect ratio.

    I'm having trouble translating all of to Unity code...ensuring that what is seen on an iPhone 6 is the same for iPhone 4 or 5 etc.

    1 - What is Orthographic Size and how do I use it (if I am even suppose to) for multiple resolutions. I've read that you just pick a random value and work from there.

    2 - I've seen this equation many times around:
    var height = 2 * Camera.main.orthographicSize;
    var width = height * Camera.main.aspect;

    What's the difference between height (as resolution of the iPhone) and height of the Camera and how do I relate the two so that sprites are rescaled appropriately across iPhone sizes?

    Thank you
     
    ALaster34 and Dumitru like this.
  2. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    Hi

    Orthographic size dictates how much the camera sees vertically in World Space units (not screen pixel resolution). So if you set it to 5, it means, you can move your character 10 units (transform.position.y) from top the bottom. You should pick a value that is meaningful to you so when you code your movement/placement, it makes sense. Think board/match-3 games. The width, in world space, is determined by the aspect ratio.

    This world space is then projected onto a physical screen where its resolution in independent of this ortho size. That means, for iPhone 6+ in landscape, 10 world space units is mapped to 1080 pixels. This gives 108 pixels per world space unit.

    The engine then determines how much world space a sprite should occupy by looking at the sprite's texture resolution and the PixelsPerUnit settings. If you set the PixelsPerUnit to 64, on a sprite with resolution of 64x64, then the engine will render 64 pixels per world space unit , effectively taking 1 unit. If the texture is 128x128, it will take 2 world space units (on each dimension) to render it. This effectively means, the engine is rendering 64 pixels of texture in 108 screen pixels (following the iPhone6 example above).

    So the golden question that most people ask is, how to make my game pixel perfect? The task is just ensuring that the number of pixels of textures that gets rendered per world space units matches the number of hardware screen pixels per world space units. You can do this by tweaking the PixelsPerUnit, Orthosize and texture resolution.

    The next piece of the puzzle is to have several asset resolution to cater for the vast differences of screen sizes (iPad Retina vs old android). This can be done using AssetBundle Variants. See this: http://forum.unity3d.com/threads/working-multi-resolution-sprite-sheets.274683/

    (I should turn this into a blog post).
     
    Last edited: May 28, 2015
  3. ALaster34

    ALaster34

    Joined:
    Mar 20, 2012
    Posts:
    21
    Not sure if I should reply but I didn't have to post and ask this question.
    Getting my studies done.
    Thank you.
     
  4. aaronkchsu

    aaronkchsu

    Joined:
    Oct 24, 2015
    Posts:
    1
    Amazing Answer!