Game Development Reference
In-Depth Information
The next bit of code figures out how big the text message is. After that, you start
laying out the controls and positioning the dialog in the center of the screen. The
idea here is to find the number of buttons you
re going to add, place them in a verti-
cal stack at the bottom of the dialog box, and add up all the space you
'
'
re going to
need to make sure there
s enough room to have the buttons and the text. The button
width, height, and border of the dialog box are given sizes relative to the overall
screen. This automatically scales your dialog box with the pixel width and height of
the game screen. A more complicated but better system would be one that takes
screen aspect ratio into account which is especially useful for games that run in
4:3 or 16:9 screens, which are typical of console games. Smart phone games can
even do 9:16 if they run in portrait orientation.
One good solution to this tricky problem is to write some code that lets you specify
how you want user interface controls anchored. Instead of anchoring them as you see
here, by the upper-left corner only, you could anchor them from the center of the
screen, top left, bottom left, and so on. This gives your user interface some flexibility
to have members float and adjust themselves to multiple screen configurations. I
could probably write a whole book about those problems alone. For now, we
'
'
ll stick
to the basics and go with a less flexible but easier to understand system.
16:9 Does Not Equal 16:10
Red Fly was working on a cooking game for The Food Network and Namco
Bandai called The Food Network Presents: Cook or Be Cooked. As we were
going through our final testing, we received word from Namco that the
screens that pop up at the beginning of all Wii games warning you not to
throw Wii remotes through your nice new plasma TV weren
'
t correct, and
they were stretched slightly. Red Fly
s user interface programmer looked hard
at the problem, and after many hours of searching for the problem realized
with horror
'
t
actually 16:9 at all. It, as every other monitor at Red Fly, was actually 16:10.
It turned out that Namco
that
the display he was using, a nice Dell monitor, wasn
'
s test team found something that every other game
publisher and Nintendo missed until then.
'
If you are positioning user interface controls by the upper left-hand corner, centering
is done by subtracting the inner width from the outer width and dividing by two:
m_PosX = (g_pApp->GetScreenSize().x -m_Width)/2;
m_PosY = (g_pApp->GetScreenSize().y -m_Height)/2;
If you subtract the width of the dialog from the width of the screen and divide by
two, you
ve got the X position that will center the dialog. Switch all the parameters
for heights, and you
'
'
ll have the correct Y position. You see that kind of thing a lot,
 
Search WWH ::




Custom Search