10
\$\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\$
  • \$\begingroup\$ Are you talking about a 3D sprite? Or UI 2D sprite? \$\endgroup\$ – TomTsagk Jul 31 '18 at 11:14
  • \$\begingroup\$ A 2D Sprite..... \$\endgroup\$ – Faizan Khan Jul 31 '18 at 13:29
18
\$\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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.