11
\$\begingroup\$

I have a Sprite with 1080x1920 resolution. And I set the Game View Resolution also to 1080x1920. What I was thinking is that the sprite (1080x1920) should fit correctly within the Camera View.

resolution of image is 1080x1920

But when I drag that sprite, the sprite is enlarged and goes out of the camera view.

screen view, sprite is out of camera

What adjustments do I need to do to make sure this sprite is 100% fit within the camera view. I could have changed the Sprite Transform Scale. But that will cause problems because I've a lot of other sprites to deal with and they should be proportional.

\$\endgroup\$
2
  • \$\begingroup\$ Are you talking about a 3D sprite? Or UI 2D sprite? \$\endgroup\$ Commented Jul 31, 2018 at 11:14
  • \$\begingroup\$ A 2D Sprite..... \$\endgroup\$ Commented Jul 31, 2018 at 13:29

1 Answer 1

19
\$\begingroup\$

This makes sense when you recall that sprites aren't just being blitted pixel-for-pixel onto your screen (which would make it a nightmare to get the same look on screens with different resolutions, since they'd all crop your art differently), but rather they're part of your 3D world in a device-agnostic gameplay coordinate system that you can control.

Like everything else in that gameplay world, the portion that ends up mapping to the screen is determined by how you've configured your Camera object.

So, there are four parts that decide how large your sprite is shown:

  1. The source resolution of the sprite.

  2. The Pixels per Unit setting chosen in its import settings inspector.

    This sets a conversion factor for transforming sizes from pixels in texture space to units in world space (ie. the space in which all your gameplay & physics calculations happen)

    Height in World Units = Source Height in Pixels / Pixels per Unit

    You should generally choose this number to align with some relevant gameplay metrics in your game. eg. if you have a tile grid with a spacing of 135 pixels, choosing Pixels per Unit = 135 will make each cell of your grid exactly 1 unit wide in the game's coordinate system, making your calculations more convenient.

  3. The orthographic size of your camera.

    (Or, if using a perspective camera, a combination of the camera's field of view and the depth from the camera to your sprite)

    This determines how many units of your world your camera can see, from the center of its view to the top edge.

    Portion of Camera Height Occupied = Height in World Units / (2 * Camera Ortho. Size)

    So if we run with the 135 PPU value, 1920 pixel tall sprite will be 14.222222 units tall in the world, meaning we'll need a camera with a height of 7.111111 to capture the whole thing top to bottom (since camera height is measured from the middle out)

  4. The pixel size of your window / output screen resolution.

    By default, the camera's view will fill the screen vertically, so if your screen/window changes in height, the vertical crop of your scene won't change (an object at the top edge or bottom edge of the screen won't move or get cropped out, the whole scene will just get larger or smaller to fill the available height).

    So the number of world units your camera can see from top to bottom maps to the number of pixels in your window/screen from top to bottom.

    Output Pixel Size = Portion of Camera Height Occupied * Height of Window in Pixels

    So if our screen is 1920 pixels tall, and our source sprite exactly fills the camera's view, then it will be output across the whole 1920 screen pixels in 1:1 alignment.

\$\endgroup\$
3
  • \$\begingroup\$ I'm really thankful to you for your detailed answer!!!! \$\endgroup\$ Commented Jul 31, 2018 at 13:30
  • 4
    \$\begingroup\$ I'm glad you found it useful! I've written a few other Q&As about working with sprite sizes in Unity that might also help: on choosing sprite sizes, on matching the appearance of different-sized sprites, on scaling pixel art \$\endgroup\$
    – DMGregory
    Commented Jul 31, 2018 at 13:45
  • 1
    \$\begingroup\$ Thanks.... I also followed you on Twitter... I'm feeling really good to have interacted with some person working at UbiSoft :) \$\endgroup\$ Commented Jul 31, 2018 at 13:47

You must log in to answer this question.

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