Search Unity

How to deal with different resolutions on mutiple platform?when making a 2d Game

Discussion in 'Scripting' started by LI LONG, Mar 29, 2013.

  1. LI LONG

    LI LONG

    Joined:
    Feb 28, 2013
    Posts:
    55
    :D
    I think I really have a big trouble...
    I want to make a cross-platform game, then different platform have different resolution ratio for sure...
    and when I use a camera with orthographic projection, I can't show my game correct...
    I don't have a very clear concept of the parameter "orthographicSize", what does it really mean?
    and I can't just get a algorithm to adjust orthographicSize to make my game fit visible on each resolution ratio
    (for example:1024x768, 960x640,800x600, 480x320,1136x640,etc)
    thank you!
    and my question is:
    is there a script that adjust the orthographic camera to adapt different resolution ratios?and maybe a package, or any
    reference related...
    thanks~
     
    Last edited: Mar 30, 2013
  2. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,250
    well unity automatically handles multiple resolutions to a degree.

    What exactly do you want to do?
     
  3. LI LONG

    LI LONG

    Joined:
    Feb 28, 2013
    Posts:
    55
    slow down and have a pray...don't be nervous...
    have a deep breath...
     
  4. LI LONG

    LI LONG

    Joined:
    Feb 28, 2013
    Posts:
    55
    yeah, I think I really have a big trouble...
    I want to make a cross-platform game, then different platform have different resolution ratio for sure...
    and when I use a camera with orthographic projection, I can't show my game correct...
    I don't have a very clear concept of the parameter "orthographicSize", what does it really mean?
    and I can't just get a algorithm to adjust orthographicSize to make my game fit visible on each resolution ratio
    (for example:1024x768, 960x640,800x600, 480x320,1136x640,etc)
    thank you!
    and my question is:
    is there a script that adjust the orthographic camera to adapt different resolution ratios?and maybe a package, or any
    reference related...
    thanks~
     
  5. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    I think most, if not all those resolution settings exist in the editor. Look at your game tab. There is a drop down menu to set the resolution.
     
  6. LI LONG

    LI LONG

    Joined:
    Feb 28, 2013
    Posts:
    55
    er....I got the answer...
    and I have made a terrible mistake...

    and here is my answer, I got the idea from cocos2d-x

    mainCamera = GetComponent<Camera> ();

    // float allScreenShowHeight = Screen.height/oneUnityUnitPixel/2.0f;
    //// float nativeResolutionWidth =
    float m_fScaleX = Screen.width *1.0f / nativeResolutionWidth;
    float m_fScaleY = Screen.height *1.0f / nativeResolutionHeight;

    // scaleX =
    // float nativeAspect = (float)nativeResolutionWidth / nativeResolutionHeight;
    float currentAspect = Screen.width*1.0f / Screen.height;

    if (m_fScaleX > m_fScaleY)
    {
    // s = pixelWidth / nativeResolutionWidth;
    mainCamera.orthographicSize = nativeResolutionHeight / 2.0f / oneUnityUnitPixel;
    }
    else
    {
    mainCamera.orthographicSize = nativeResolutionWidth/oneUnityUnitPixel*(1.0f/currentAspect)/2.0f;
    }
     
    Last edited: Mar 30, 2013