Game Development Reference
In-Depth Information
To reposition the text, the quads are simply recalculated. This isn't the most
optimal way, but it's very simple to code and highly unlikely to ever cause a
bottleneck in game programming.
A function to alter the color of the entire text would also make things more
convenient.
public void SetColor(Color color)
{
_color = color;
foreach (CharacterSprite s in _bitmapText)
{
s.Sprite.SetColor(color);
}
}
In this snippet, the
Text
has a color member; this stores this current color of the
text. When
CreateText
is called, all the vertices are remade including the
color component. With the current color stored in the text class, the vertices can
be remade maintaining the
Text
color. An overloaded
SetColor
function is
added (doesn't require a color parameter) for use in the
CreateText
function.
public void SetColor()
{
foreach (CharacterSprite s in _bitmapText)
{
s.Sprite.SetColor(_color);
}
}
At the end of the
CreateText
function, an extra line needs to be added
SetColor();
The width and height of the text is very important when trying to align text on
the screen; therefore, a way to measure a text string in pixels would be useful.
A
MeasureText
method in the
Font
class will give this functionality.
public Vector MeasureFont(string text)
{
return MeasureFont(text, -1);
}
Search WWH ::
Custom Search