Game Development Reference
In-Depth Information
Cameras: Orthographic Size
Perhaps the most common question I'm asked about 2D development in Unity is, “How can I make
a sprite appear on-screen at its true pixel size, minus all perspective distortion?” This question is,
in essence, about pixel perfection . Perhaps you've created an image in Photoshop or GIMP, and
you want it to display in an orthographic camera at exactly the same size as the image file—pixel
for pixel. This section explores this issue as we scale and size the punch weapon to fit the weapon
camera. In short, the ultimate render size of an orthographic camera is controlled using the Size
member—although this member works in conjunction with other settings, as we'll see. This member
determines how world units relate to pixels (see Figure 6-13 ).
Figure 6-13. The size member of orthographic cameras controls the size of graphical elements on-screen
The main question for a developer interested in achieving pixel perfection from orthographic
cameras is, “What value should size be for an orthographic camera?” To achieve a 1:1 ratio between
world units and pixels, the size value should be half the vertical height of the game window in pixels
(That is: Size = pxHeight/2 ). Thus, for games with a resolution of 1024×768, a size value of 384
(768/2) is correct. This seems simple enough: but give it a try for CMOD.
There's a problem. Even if we set the camera size to 384 and the resolution to 1024×768 from the
Game tab, the weapon sprite appears too small—it's barely visible. We know something is wrong
because the game texture size is 4096×4096 pixels, and the punch weapon within that texture has
been explicitly sized for a 1920×1080 HD display. This means, the weapon should appear much larger
than it does with a camera setting of 384, where 1 unit should equate to 1 pixel (see Figure 6-14 ).
So what's wrong?
 
Search WWH ::




Custom Search