Sunday, December 4, 2016

How can I set up Unity so that 2d images are displayed in their original resolution?


I took images from my iOS game that I am developing in SpriteKit and put them in a Unity Android 1136x640 screen, which are the same dimensions for the iOS game but the images are a lot smaller. How can I get a similar representation that coincides with the screen size? I would like a 284x640 image to be displayed to take a quarter of the screen width, which is what happens in reality.



Answer



There are several things which affect sprite scaling in Unity.



  • When you import a sprite in Unity, there is a setting Pixels per unit for the sprite asset in your project folder structure. Use this setting to scale the sprite.


  • All Game objects have a Scale X, Y and Z in their Transform-component which makes them larger or smaller. Note that the scale of a parent game-object also affects all of its child-objects.

  • When your camera is set to Projection: Orthographic, then the property Size defines how many units fit on the screen.

  • When your camera is set to Projection: Perspective, then objects closer to the camera will look larger than those further away. The Field of View also allows you to control the zoom factor.


When your camera is orthographic, then the vertical height of the viewport in Unity units is twice the camera size. That means to get 1 px image = 1px on screen, set the Pixels per unit to your vertical screen resolution divided by twice the camera size.


When you have a camera size of 5 (default) and you target a 640px high display, set the ppu to 640 / (5 * 2) = 64.


You might also want to set the Filter Mode of your images to "Point (no filter)" to avoid sprites getting blurred when their positions are not perfectly on-pixel.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...