appraise the first simple project
World Unit and Pixel Correspondence :These questions arise because
of confusion about how Unity’s world space relates to pixels on-screen. When
you select an object in the scene and examine its world position in the Object
Inspector, the numbers you see correspond to world units and not pixels. But, in
2D games we often do want to specify object locations and sizes and movement
in terms of pixels.
2Pixel Perfect Textures
Further, setting the size or scale of an object to
512×512×512 world units will not solve the issue on its own either, because the
appearance of objects depends critically on the camera position, its field of
view and its projection type. The problem this raises is that of pixel perfection.
In 2D games we often need to guarantee that textures will be shown on-screen
exactly as they are defined in the image files, without drastic resampling, without
distortion, and without resizing.
3
Non-Power-2 Textures: Square textures are all well and good for texturing
3D objects where textures can be tiled, flipped, mirrored, overlapped, and
UV edited. But in the world of 2D we often have many sprites and objects of
different shapes and sizes, and we want to maintain these sizes without the
constraints of power-2 textures. We’ve seen already how we can overcome this
restriction by using GUI textures, but again these types are not intended for
3D objects in the scene. For those, we typically use regular textures and these
will always scale non-power-2 textures to the nearest power-2 size, and this
resampling and scaling is not what we want. There are exceptions to this rule:
it is possible to configure textures in Unity to avoid this scaling, even non GUI
textures. But as a general principle we’ll want to keep the textures a power-2
size, but find a way to overcome the limitations this brings. We’ll see how to do
this later.
4
Draw Calls and Textures: If you run the Alien Invasion game right now and
check the Stats panel in the Game tab, you’ll see an interesting statistic under
the Draw Calls field. The number of draw calls relates to the number of different
materials being used in the scene. If we have a scene with one player space ship
and ten enemies, there will be a total of two draw calls because all these objects
together rely on only two different materials—one for the player and one for the
enemy. If we add an ammo material and show an ammo object on screen, then
we add a further draw call, and so on for each separate material. If all the sprites
and graphics for a 2D game are divided up into separate and multiple files like
this, then we incur a greater performance penalty for each new object or sprite
we add to the game. Better is to paste all the sprites and textures into one larger
texture sheet (known as an Atlas Texture), and then assign the appropriate pixel
regions to the geometry in our scene through customized UV mapping.
Doing this achieves draw call batching. See here for more information:
http://docs.unity3d.com/Documentation/Manual/DrawCallBatching.html.
It allows us to reduce the number of draw calls in the scene and thereby to
improve the performance of our game.
PS
Draw Calls. This value will become especially important for us later when
developing 2D games, as we’ll see. It refers to the total number of times per
frame that the Unity engine calls on the lower-level rendering functionality to
render your scene to the screen. The higher this value, the more complex and
expensive your scene is to render. For this reason, lower values are generally to
be preferred. There are some steps and methods available to us for reducing the
number of draw calls per frame, and we’ll explore what those are throughout this
book.

浙公网安备 33010602011771号