0
\$\begingroup\$

I have a fresh Unity project, with just one 480x800 pixel image. It's platform is set to Android, and the aspect ratio in the game view is WVGA Portrait (480x800). However, the image doesn't occupy the whole screen.

The camera is orthographic, with a size of 5. My intention is to test different resolutions on the same device, and maybe test on other devices.

enter image description here

Why is the image appearing smaller, in the scene?


The project is set to 2D. I added the image firstly by pasting it directly to my Sprites folder using the Windows explorer, then by clicking Assets->Import New Asset, and got the same result. My only GameObject on scene is the one holding the image, this will be used as one of my game backgrounds.

Here are the texture import settings and the inspector for the GameObject:

2

I haven't tested anything regarding the UI on Unity yet, so no Canvas. My experience with the engine is two weeks.

\$\endgroup\$
1
  • \$\begingroup\$ We'll need to know more about your image and how you've placed it in your project/scene, since there's multiple ways to use an image file. The fastest way to get all this information without too much back-and-forth is to include a screenshot of the inspector for the GameObject displaying your image, its parent canvas (if using a UI canvas), and the import settings for the texture. \$\endgroup\$
    – DMGregory
    Jun 15, 2017 at 3:43

1 Answer 1

1
\$\begingroup\$

Your pixels per unit value in your texture import settings is 100. That means the default scale when you drop your sprite into the world will pack 100 pixels into each unit of world space - so your 480 x 800 image will take up 4.8 x 8 units of world space.

Your camera has a vertical size of 5, which is a measured as a half extent (distance from the center to the top), so in total it sees 10 units of world space vertically.

The middle 8 units are filled by your sprite, but at either side you have 1 unit of world space leftover.

The simplest fix is to change your camera size to 4 - then it will exactly match the size of your sprite in the world.

See this answer for more details on using pixels per unit and world space in Unity.

This use of world space as an intermediate between texture & screen coordinates might seem odd if you're coming from an environment that just blits image texels straight to the screen's pixels one-for-one, but it lets us do some powerful things, like...

  • Displaying consistent gameplay on multiple different resolutions (all of our behaviour uses world space, so the play experience stays the same, while the mapping of that space to the screen grid and even which sprites we use can be adjusted independently)

  • Complex transformation hierarchies, including 3D rotation (if 1 sprite texel = 1 screen pixel, then how do we foreshorten a sprite when looking at it on an angle?)

  • Mixing 2D and 3D content / effects in a single world coordinate system

\$\endgroup\$
5
  • \$\begingroup\$ Thanks, I'm reading a lot to get a grasp on it. One quick question: Since my 2D game (on portrait orientation) will not be in pixel art in order to avoid the scaling issues, is it a good idea to set a fixed size background that takes into account very wide screens so no black bars are shown on the sides, and at the same time to make sure the game elements and buttons take into account the thinest screens, so they won't be cut from some screens? that way I'll only have to set a specific height for my background and set the camera so it's fixed on the bg's height. Is this a correct approach? \$\endgroup\$
    – Adocad
    Jun 15, 2017 at 19:04
  • \$\begingroup\$ That sounds like it will work. You can also use Unity's UI system to control the scaling behaviour of your game (eg. making a control hug the right side of the screen, no matter how wide the screen gets, without stretching. \$\endgroup\$
    – DMGregory
    Jun 15, 2017 at 19:21
  • \$\begingroup\$ Isn't the UI system mainly for the menus? And I don't understand your example, what do you mean by hug the right side of the screen?... Oh wait, do you mean for example, a left and right button? so they will always remain on the sides at same location on different screens? sorry I didn't get that at first, language issue. \$\endgroup\$
    – Adocad
    Jun 15, 2017 at 19:32
  • \$\begingroup\$ The UI system is for whatever you want to use it for. ;) \$\endgroup\$
    – DMGregory
    Jun 15, 2017 at 19:39
  • \$\begingroup\$ Seems like I need to do more reading. Thanks again! \$\endgroup\$
    – Adocad
    Jun 15, 2017 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .