Game Development Reference
In-Depth Information
the video card settings, but the exact method for disabling V-Sync differs from
card to card.
Profiling
The fps counter can be used for some basic profiling. The game is currently
rendering about ten textured quads with color information (the fps text). A 2D
game might use a quad per tile and quads for the player and game enemies. Let's
be very generous and assume many particle systems, say, 10,000 quads. That's a
lot of quads to be on screen at one time and should be okay for most games.
A rough test can be done to see if the current sprite can handle this many quads.
renderer.DrawText(_fpsText);
for (int i = 0; i < 1000; i++)
{
_renderer.DrawText(_fpsText);
}
This renders the fps text 1,000 times. That's about 10,000 quads total. On my
computer, the fps goes from 1,000 plus to just over 30. Thirty is fine for most
2D games. This means most 2D games will probably be fine with the current
efficiency of the sprite code. Computers with older graphics cards may not
fair so well, so some efficiency measures will be covered toward the end of
this chapter.
Refining the Text Class
The text class is quite functional now, but it could do with some more methods
that will make it easier to use. For instance, there is no way to set the position of a
text string. There really needs to be a way to measure the text so it can be aligned.
Also, text often needs to be constrained to columns. This can be achieved by
giving the text a maximum width. If the text overflows this width, it will be
wrapped on the next line. This is a very desirable feature, especially when filling a
text box in a game.
Here's the helper method to set the Text position.
public void SetPosition(double x, double y)
{
CreateText(x, y);
}
 
 
Search WWH ::




Custom Search