Game Development Reference
In-Depth Information
This string can then be grabbed by its ID in code:
Click here to view code image
Localization .Get().Text("ui_err_money")
The code for the Localization class is not terribly complex. On load, it parses
in the XML and then populates a dictionary with the key/value pairs. The Text
function then just performs a lookup into the dictionary. With this system, it would
be relatively easy to translate the game to another language by loading in a differ-
ent XML file.
Graphics
The GraphicsManager is responsible for most of the rendering logic. When
it's first initialized, if the game is set to full-screen mode, it determines the current
desktop resolution and sets the game's resolution to that. Otherwise, it uses the
resolution that's specified in GlobalDefines . But the most important function
of the GraphicsManager class is to handle rendering of all the game objects.
A game object can specify in its constructor which draw order group it's in.
There are three possibilities: background, default, and foreground. Each draw or-
der group has its own list in GraphicsManager , so the game objects are added
to the appropriate list when they are added to the world. The purpose of the dif-
ferent groups is to allow for specific objects to always be in front of or behind the
objects that are in the default group (which is nearly all objects).
Drawing normally is done with z-buffering, which if you remember from Chapter
4 means that it only draws a particular pixel if there's nothing in front of it that has
already been drawn. However, the draw function in GraphicsManager only
enables z-buffering for the default group. First, z-buffering is disabled and the
background group is drawn. This group can be used for a skybox , foe example,
which is a cube that encompasses the entire world and has a texture of the sky (or
space). Then z-buffering is enabled and the default group, which contains the vast
majority of game objects, is drawn. Finally, z-buffering is disabled once more and
the foreground objects are drawn. This group allows for objects such as a first-per-
son model to be drawn without worrying about clipping into other objects.
There's some other functionality in GraphicsManager , but it's not as critical.
You'll find a few small helper functions for things such as drawing 2D and
3D lines as well as drawing a filled rectangle. Finally, the bloom effect on
the XNA version causes the tiles to glow. The effect is implemented as per a
Search WWH ::




Custom Search