Game Development Reference
In-Depth Information
Depending on where in the Z depth you placed the battery elements and the stork elements, you
may discover that the stork goes in front of the battery, while the bundle and Lower Beak go behind
it (Figure 9-46 ). To fix the problem, you could move the battery farther back in the scene with its Z
position, or you could adjust its Order in Layer.
Figure 9-46. The Bundle and Lower Beak behind the Battery sprite
In a fully 2D game, you would want to make use of Unity's Sorting Layers. Using these layers, which
are similar to camera Layers and accessed from the same place, you can create layers for things
like background and foreground sprites so you won't have to adjust the Z depth for every sprite on
an individual basis. The Sorting Layer is assigned to sprites in the Sprite Renderer component. The
lower element numbers are drawn first, so you would create a background layer first, a character
layer next, and then a foreground layer.
In this game, there are very few sprites and they are currently all on the same layer, the Default
layer. Let's use the “Order in Layer” parameter to move the two battery sprites back behind the
stork sprites.
9.
Select the Battery_0 sprite, and give it an “Order in Layer” value of -1 .
That immediately puts it behind Battery_1, the energy bar.
10.
Set Battery_1's “Order in Layer” value to -2 .
The energy bar is back behind the outline.
11.
Click Play, and watch as the stork flies over the battery.
The Stork and bundle are now both in front of the battery sprites during the fly-by (Figure 9-47 ).
 
Search WWH ::




Custom Search