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

Comprehensive guide concerning 2d and different aspect ratios/resolutions

Discussion in '2D' started by Todiloo, Jan 22, 2016.

  1. Todiloo

    Todiloo

    Joined:
    Jan 22, 2016
    Posts:
    53
    I have been googling but not finding a comprehensive guide about creating 2d games in unity and how to setup camera/create assets so I can get the same experience in multiple phones.

    I want to have a game which is in portrait mode, I want the entire screen to be the game area(so basically no moving the background), what do I need to think about and how do I set this up. Is there a guide guide/information out there about this? I find bits and pieces here and there (a lot for unity <5).

    Say I want a game area like this:


    Then a different sizes phone shouldn't allow for more bubbles ...

    I will create a similiar game and well then I need to snap onto some sort of grid and how do I handle the positions?
     
    Last edited: Jan 22, 2016
  2. ToyBrain101

    ToyBrain101

    Joined:
    Sep 15, 2014
    Posts:
    13
    you must create a game like this using uGUI and anchors within that system. the positions can be created and snapped to from off the camera position. you can manipulate any configuration using anchors and screen space overlay.
     
  3. Todiloo

    Todiloo

    Joined:
    Jan 22, 2016
    Posts:
    53
    Do you mind explaining why I need to use the GUI system and not regular sprite? I must admit I havent worked with the GUI system for a long time but I guess I cant use any 2d physics and such ...
     
  4. Kurius

    Kurius

    Joined:
    Sep 29, 2013
    Posts:
    412
    You don't necessarily need to do what ToyBrain101 said. Unity 5.x automatically resizes your game based on the HEIGHT of the device. This means that on narrow/long devices you'll simply see extra space on the top/bottom of the screen, but your game pieces will automatically be rescaled to fit the middle area of the screen. Then you can readjust your header/footer text (like your score) at runtime to more nicely fill up the extra space at the top/bottom of the screen. You can use Camera.main.aspect to detect if it's a narrow/long device, or a wide/short device.
    You can even use my simply code to handle portrait/landscape orientation user rotation...
    http://forum.unity3d.com/threads/so...one-auto-rotation-orientation-changes.380668/
     
  5. ToyBrain101

    ToyBrain101

    Joined:
    Sep 15, 2014
    Posts:
    13
    You don't need to use the GUI system. However, once you understand how the anchors work as well as tween. You will realize that it can become very polished. Just a suggestion.
     
  6. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    831
    if you want extremely accurate camera sizes, I'd recommend the 2DToolKit asset, it has probably the best camera setup I've ever worked with.

    If you're going for the same experience on different phones, you will need to make compromises. Even Candy Crush enforces a gameplay area. Your job is to mask the unused area well, so the user doesn't notice ;)

    Unity uGUI works a bit like responsive CSS, you can get similar layouts on most devices.
     
  7. Todiloo

    Todiloo

    Joined:
    Jan 22, 2016
    Posts:
    53
    I am not looking for a pixel perfect setup but a good looking one that doesnt require too much work/effort to use. Also I want to see the portrait mode in the editor when I testrun. Having to like create a background outside the gamearea for supporting multiple resolutions is fine.
     
  8. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    At the top left of your game view, you can specify a resolution or aspect ratio for previewing.

    You can also do this in your Canvas object for UI scaling. In the "Canvas Scaler" component, set it to "Scale With Screen Size", and set your target resolution. As you resize your game view, your canvas should reflect that size in the scene view (keep in mind that your scene view doesn't represent the end result unless it's a WorldSpace canvas, as the Overlay or Camera Canvas maps to screen coordinates). You could do this with an Overlay canvas to mask out the portion of the screen that will never have gameplay.
     
    Last edited: Jan 27, 2016