Search Unity

2d Vertical Game

Discussion in '2D' started by Dumitru, May 27, 2015.

  1. Dumitru

    Dumitru

    Joined:
    May 7, 2015
    Posts:
    80
    Hello, so I'm making a 2d game that plays in the mobile's vertical position, what would be the best way to make it avaible on all platforms without having to resize it for each mobile's screen size?

    Thank you for taking your time to read this post!
     
  2. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    If you don't mind having your assets scaled, then running on screens of different sizes are trivial.

    All you have to do is make sure that you leave some space horizontally to cater for some 'trimming' on narrower screen or extra space on wider screens. Have a play with the game mode window by resizing it while in game mode to see how it effects your game.

    If you want your art to be displayed in pixel perfect manner, then the complexity multiplies quickly. It would involve carefully tweaking the camera's ortho size, the sprites' PixelPerUnit against the target device's native resolution.
     
  3. Dumitru

    Dumitru

    Joined:
    May 7, 2015
    Posts:
    80
    So basically if i make it fit in a 4:3 but make the level 16:9 , it would work on all devices,
     
  4. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    Yes, you will have lot of space to the right and left. You can quickly try this out in the in the game view by switching between 16:9 and 4:3, notice how it will maintain the vertical 'world space' but the sides will grow/shrink.
     
  5. Dumitru

    Dumitru

    Joined:
    May 7, 2015
    Posts:
    80
    yeah, I see, will it change the image quality?
     
  6. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
  7. gavinb80

    gavinb80

    Joined:
    Nov 4, 2012
    Posts:
    98
    I've handled the issue of screen sizes and aspect ratios by ensuring my background / game area would fit within the size of most (maybe not all) screen sizes and then have a script on the camera that adjusts the orthographic value of the camera to fit the width of the background image.

    This then cuts of some of the top/bottom of the background which doesn't make any difference to game play and keeps all sprites looking as I intended.
     
    theANMATOR2b likes this.
  8. Dumitru

    Dumitru

    Joined:
    May 7, 2015
    Posts:
    80
    Can you tell me how did that? Or explain to me how a script like that works? Thank you so much :)
     
  9. gavinb80

    gavinb80

    Joined:
    Nov 4, 2012
    Posts:
    98
    No problems, I will post the script for you shortly
     
  10. gavinb80

    gavinb80

    Joined:
    Nov 4, 2012
    Posts:
    98
    This is what I use ( to fit to either width of height ) and seems to work ok for me (although not sure if it is the best, or correct way to be honest). Apply the script to a camera, then in the editor drag the sprite you want to size to into the relevant property. If you tick the Fit Width tick box it'll fit the camera to the width of the sprite, else it will scale to the height (in my case 98% of the height)

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using UnityEngine;
    4.  
    5. public class CameraFit : MonoBehaviour {
    6.    
    7.     public SpriteRenderer spriteToFitTo;
    8.     public bool FitWidth = true;
    9.    
    10.     void Start () {
    11.         if(FitWidth) {
    12.             Camera.main.orthographicSize = (float)((spriteToFitTo.bounds.extents.x * Screen.height) / (Screen.width ));
    13.         }
    14.         else {
    15.             Camera.main.orthographicSize = (float)((spriteToFitTo.bounds.extents.y * Screen.width) / (Screen.width )) * 0.98f;
    16.         }
    17.     }
    18. }    
     
  11. Dumitru

    Dumitru

    Joined:
    May 7, 2015
    Posts:
    80
    alright, thank you alot :)
     
    gavinb80 likes this.
  12. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    Well, as long as you can account for the changing visible vertical world space then this is OK.