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

Getting my background to scale in a predictable way

Discussion in '2D' started by omatase, Sep 4, 2014.

  1. omatase

    omatase

    Joined:
    Jul 31, 2014
    Posts:
    159
    I have an image that is 1217x601 (don't ask why, I'll find a different resolution for it at some point). But when I put this image on my game intending it to be the background for my scene it's displayed with a huge margin around all sides.

    In the image example here the screen size is 1207x679 so I would expect the graphic to crop on the top and bottom and not quite fill the width. Either that or it would scale to fit vertically and then leave a bigger gap on the sides. Either of those I could see being reasonable outcomes, however the results below are what I get.

    Also note the inspector values on the right are those currently being used for the background game object.

    example 1.jpg
    Additionally, here are the camera settings for the scene

    example 2.jpg

    Any help much much appreciated!

    Thanks
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    camera ortho size influences the coordinate system and changes the scale of all objects.
     
  3. omatase

    omatase

    Joined:
    Jul 31, 2014
    Posts:
    159
    Is there a size, for instance 10, that I could set the ortho camera to that would cause 1 pixel to appear as 1 pixel on the screen? So that if I have a 800x600 image for instance, it would take up an 800x600 pixel area when the game is running?
     
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    depends totally on the size of the geometry. If you had 10, your geometry would need to cover 80x60 units in coordinate space, ie that's the scale of your rectangle. I think.
     
  5. velipekka

    velipekka

    Joined:
    Jun 2, 2014
    Posts:
    9
    Here's a video that explains some things on how to work with 2D camera in Unity:


    You can download the project files from here:
    goo.gl/6oSzDx

    I hope this helps :)
     
  6. omatase

    omatase

    Joined:
    Jul 31, 2014
    Posts:
    159
    Thanks for your replies. I am sad to report that they did not provide me with the answer I'm looking for, however I ended up just going through all of the 1-hour live training tutorials one at a time and finally this video did end up helping: http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/2d-catch-game-pt1.

    I'd love positive reinforcement that the conclusion I came to was the correct one though if anyone feels so inclined to indulge.

    What I have decided the answer to the question is that I should avoid trying to concern myself with pixels as much as possible and instead rely on a combination of Unity Units, viewport points and world points to align and scale my game. What I ended up doing was not really caring what size my background was so long as it wasn't too big or too small. It could be bigger than I need, just not inefficiently so. I then just made sure my background was big enough and the right aspect ratio (in this case 1920x1080, 16:9). At that point, I can choose my ortho camera size, although I'm sure there are advantages to just leaving it as the default so that's what I did. Lastly, if my image was either too big or too small by just a smidge I could adjust the Pixels to Units property of my image. In my case none of these were necessary after I resized my background image to 1920x1080.

    Appreciate any feedback!