Orthographic screen size

Discussion in 'iOS Development' started by Risine, Nov 29, 2011.

  1. Risine

    Risine

    New Member

    Joined:
    Dec 10, 2009
    Messages:
    114
    I'm making a "2D" game using 3D planes and an orthographic camera.
    My base is a 640x960 screen and I want to have a 1:1 pixel in this screen size to place all my elements.
    I'm using an orthographic size of 960/2 = 480, but the width is not 640 but seems to be 720???

    1/ What can I do to get the right width?
    2/ What can I do to make the game view being the same whatever screen size is used? ( elements should be automatically scaled ).
     
    Last edited: Nov 29, 2011
  2. TrialByFun

    TrialByFun

    Member

    Joined:
    Jun 23, 2009
    Messages:
    92
    Hi,

    The 720 width you are getting is from multiplying the aspect ratio of the screen by the orthographic height;

    Aspect = (width / height)
    = (960 / 640)
    = 1.5

    Orthographic width = Orthographic size * aspect
    = 480 * 1.5
    = 720

    The confusion here is that Orthographic size is actually related to the height of the viewport

    http://unity3d.com/support/documentation/ScriptReference/Camera-orthographicSize.html

    So for your game you'll want to set size to (screen height / 2 )
    = 640 / 2
    = 320


    Hope that helps
     
  3. Risine

    Risine

    New Member

    Joined:
    Dec 10, 2009
    Messages:
    114
    Thanks SBurgess , that's "almost" clear for me.

    Just one thing I don't understand.
    If I want a width of 640, I should have :
    640 = Size * 1.5
    Size = 640 / 1.5 = 426.666 and not 320 ????
     
  4. TrialByFun

    TrialByFun

    Member

    Joined:
    Jun 23, 2009
    Messages:
    92
    Is your game screen 960 tall and 640 wide?
     
  5. Risine

    Risine

    New Member

    Joined:
    Dec 10, 2009
    Messages:
    114
    My game screen is width = 640 and height = 960 ( portrait )
     
  6. TrialByFun

    TrialByFun

    Member

    Joined:
    Jun 23, 2009
    Messages:
    92
    Well you were doing the right thing to start with Orthographic size of 480.

    The only reason with width would be wrong is if your not actually running the game at the screen size you thought. Is the window squashed in the editor by any chance?
     
  7. Risine

    Risine

    New Member

    Joined:
    Dec 10, 2009
    Messages:
    114
    Ok, seems like I was wrong positioning my background. And 480 is the value ( Screen height / 2 ). Thanks.
     
  8. Risine

    Risine

    New Member

    Joined:
    Dec 10, 2009
    Messages:
    114
    Oh well, here I come again on this subject, it wasn't that clear indeed after all.
    I can't find any logical equation about that :
    Let me resume :
    I place my elements based on a 640 width x 960 height (in unity units).
    I'm using an orthographic camera.
    WHAT I WANT : I want my 640 width to fit the phones screen width whatever width it is.
    my results depending on screen size :
    320x480 -> Ortho size = 480
    480x800 -> Ortho size = 530
    480x854 -> Ortho size = 560
    640x960 -> Ortho size = 440
    Does someone has an idea of the equation to get the correct ortho size depending on screen width and height?
     
  9. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,590
    normally it would be: 640.0/screenwidth * screenheight/2

    Basically you take the normal orthogonal equation for "unity unit to pixel" (screenheight/2) and scale it by the desired 'normalized screen width' of 640 pixels which is 640/screenwidth. This gives you basically your values which you likely got from 'trial and error' search (cause it would be 533.333 for 480x800 for example or 569.xx for 480x854)

    question is why 640x960 is that seriously wrong cause that one should be 480, for all others its within the range of 10 pixels at maximum where it goes wrong (trial and error tolerance)
     
    Last edited: Dec 14, 2011
  10. Risine

    Risine

    New Member

    Joined:
    Dec 10, 2009
    Messages:
    114
    That works perfectly, thanks Dreamora.
     
  11. arachnid

    arachnid

    New Member

    Joined:
    Dec 18, 2011
    Messages:
    11
    I am having a similar issue and having trouble understanding how this should work.

    Suppose I have a background image texture which is 640width by 960 height that I would like to display pixel per pixel on the IOS 4 retina display. I imported this texture as an asset and changed the advanced option for "non power of 2" to none.

    I have set up an orthographic camera with size 5 and normalized viewport rect of
    X = 0 Y=0
    W = 1 H=1.5

    I have created a plane and added my texture to it. I then rotate the plane 90 X and 180Y so that it faces the camera.
    I scale the plane X = 1 y =1 X = 1.5

    At this point, I would hope that when I build the app, it would should show me my background exactly fit to the Iphone 4S retina display. This does not appear to work properly for me, I see most of my background but it is appears cut off from the top.

    Any thoughts on what I may be doing wrong?

    Thanks!
     
    Last edited: Dec 18, 2011
  12. zfz.zahid

    zfz.zahid

    Member

    Joined:
    Apr 21, 2014
    Messages:
    1
    hey Risine how should i set my project that should run on different android smartphones