Game Development Reference
In-Depth Information
tactic will severely limit the kinds of devices your game can support, and will also frustrate users who
like more control over how their games are displayed. Furthermore, some mobile devices (in their
default state) don't allow users to change the resolution.
So, a more positive response from game developers is to create a single GUI with the intention of
supporting as many different screen sizes as possible . But this has troublesome implications for
GUIs, which are rendered in screen space and are intimately linked to pixels and to pixel positions.
In particular, if you can't know in advance which screen size a gamer will use for your game, then you
can't reliably position GUI elements on screen in terms of pixels and expect a consistent experience
and look for all users. While 512 pixels is the horizontal center for a 1024 pixels-wide display, it will
not be so for a 2048 pixels-wide display (there, it'll be a quarter width). And this problem applies
for any screen sizes and for both dimensions (X and Y), across all devices and all pixel values. This
tells us that specifying the positions of GUI elements in absolute pixel values can't help much, if we
want to create multiresolution compliant GUIs—that is, a single GUI system that works across all
resolutions ( resolution independence ). One solution to this problem (chosen here) is to develop a
relative positioning scheme, known as anchoring . Consider Figure 8-2 .
Figure 8-2. Configuring a dedicated UI camera
Using anchoring, positions are specified not in terms of absolute pixels, but as normalized offsets
from a fixed and static screen position known to remain constant across all possible resolutions.
In Figure 8-2 , the screen center is specified as (0.5, 0.0) from a left-center anchor on screen. Thus,
the left-center anchor is positioned at (0.0, 0.5), and is always half the vertical height of the screen.
And the anchored square at the screen center is offset from that point by (0.5, 0.0), meaning half
the horizontal width of the screen. This form of relative positioning is powerful because it lets you to
resolve screen positions across multiple resolutions, simply by expressing positions as proportions
rather than absolute pixels. With this technique in mind, let's create a GUIObject class, which will
act as a relative-positioning component for any GUI objects we create. This component will be a
 
Search WWH ::




Custom Search