Search Unity

Can i force all android devices to show a particular size image in symmetry

Discussion in '2D' started by sahilshjmu, Sep 19, 2017.

?

Is this thing possible or not with Unity

  1. Yes its possible

    0 vote(s)
    0.0%
  2. Nope

    0 vote(s)
    0.0%
Multiple votes are allowed.
  1. sahilshjmu

    sahilshjmu

    Joined:
    Aug 18, 2017
    Posts:
    10
    May be my topic heading is not too good but i am unsure what to ask at top because my problem is same as many out there is having with no proper solution.
    Here is my Issue:
    I want to develop an Android Portrait game whose background Image is of size 720*1280.

    I just shifted from Corona sdk to Unity, In Corona there was a config file which takes screenWidth and Height and there if i enter 720 and 1280 respectively then all devices no matters if 320*480 or 640*960 or any size, it will adjust its pixels in a way that the 720*1280 image will fit exact full on the screen with no bleed areas anywhere.

    Now in Unity i have seen there is no such file and so i am little confused as what base size should i target which later will be scaled automatically according to any device.

    Let me explain in small words too: I want to make a Unity game with background size as 720*1280 and i want it to fit on all mobile devices and be show exactly same at all 4 corners.

    Please help me in doing this. I am using 2D game with Sprite Image and Sprite Rendering method.

    Thanks in Advance,
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    In Unity your camera will always change aspect ratio to fit the device. Look into Canvas and Canvas Scaler for automatic UI resizing. For sprites, you'll need to do a little bit of math to rescale them to fill a screen of any aspect ratio.
     
  3. gsgames

    gsgames

    Joined:
    Apr 20, 2015
    Posts:
    4
  4. sahilshjmu

    sahilshjmu

    Joined:
    Aug 18, 2017
    Posts:
    10
    Hello Jeffreyschoch: Thanks for the reply. I have been trying this solution from many day and found that i am in comfortable position with Canvas and Canvas Scaler and i have used that very well, all my buttons are now aligning very well on screen. Main issue is still the background image and other items on the screen.

    EG: say i have an image of 720*1280 size in partrait mode and i want to fit it on every screen so it will not be cut down, Right now i have seen that changing aspect ratio is making trick but somehow if i want to fit the height then a bleed area is also visible at horizontal ends.

    Please help me to understand this a bit more so i can kick start my first project in Unity.

    Thanks
     
  5. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Are you saying you want the background image to be stretched to fit any screen?

    If that image is a UI object, (has a RectTransform), then you can set the anchors at the top left of the RectTransform component to stretch in both directions, which will fill the parent if the Left/Top/Right/Bottom offsets are 0.

    If it's a Sprite object, you'll need to do a little bit of math to change the scale of it to fit the screen, which I can go into more detail about if you confirm it's a sprite.
     
  6. sahilshjmu

    sahilshjmu

    Joined:
    Aug 18, 2017
    Posts:
    10
    Hello Jeffreyschoch,

    Thanks for quik reply.

    Yes i will explain it a bit more.

    Basically i am targetting a simple solitaire game with 720×1280 size. It has some diamonds attached at 4 corners so its mandatory to show image in full without cutting any edge.

    I have achieved this today by creating a 2d game and setting image to sprite and then rendering it as sprite. So basically i made gameobject and assign image in sprite renderer. Then i write a code in script which is attached with same background and there i did a little maths and use some function xyz.ortho(-5×1.6, 5×1.6, -6.4,6.4,.0.1000)

    I am not sure how i managed to reach here but it somehow did the trick and now my image is either stretching or compressing but somehow fitting on all devices in unity as i tested.

    But if there is a better way to do this i would surely like to hear from you on that and want to test.

    Please tell me what is UI object method. Also please if you dont mind tell me which is better approach. I am totally new to this platform but want to use it for any next games.

    Thanks in Advance