Game Development Reference
In-Depth Information
The Text class needs to redefine the CreateText method to handle a max-
imum width parameter.
private void CreateText(double x, double y)
{
CreateText(x, y, _maxWidth);
}
private void CreateText(double x, double y, double maxWidth)
{
_bitmapText.Clear();
double currentX = 0;
double currentY = 0;
string[] words = _text.Split(' ');
foreach (string word in words)
{
Vector nextWordLength = _font.MeasureFont(word);
if (maxWidth != -1 &&
(currentX + nextWordLength.X) > maxWidth)
{
currentX = 0;
currentY += nextWordLength.Y;
}
string wordWithSpace = word+"";//addthespace character that was
removed.
foreach (char c in wordWithSpace)
{
CharacterSprite sprite = _font.CreateSprite(c);
float xOffset = ((float)sprite.Data.XOffset) / 2;
float yOffset = (((float)sprite.Data.Height) * 0.5f) +((float)
sprite.Data.YOffset);
sprite.Sprite.SetPosition(x + currentX + xOffset, y - currentY -
yOffset);
currentX += sprite.Data.XAdvance;
_bitmapText.Add(sprite);
}
}
_dimensions = _font.MeasureFont(_text, _maxWidth);
_dimensions.Y = currentY;
SetColor(_color);
}
 
Search WWH ::




Custom Search