MonoGame not all letters being drawn with DrawString
- by Lex Webb
I'm currently making a dynamic user interface for my game and are setting up having text on my buttons. I'm having an odd issue where, when i use a specific piece of code to determine the text position, it will not render all of the text passed to DrawString. Even weirder, is if i insert another DrawString after this, drawing more text at a different place, different parts of the text will be drawn.
The code for drawing my button with the text attached is:
public override void Draw(SpriteBatch sb, GameTime gt)
{
sb.Draw(currentImage, GetRelativeRectangle(), Color.White);
sb.DrawString(font, text,
new Vector2(this.GetRelativeDrawOffset().X + this.Width / 2 - font.MeasureString(text).X / 2,
this.GetRelativeDrawOffset().Y + this.Height / 2 - font.MeasureString(text).Y / 2), textColor);
}
The methods in the creation of the Vector2 simply get the draw position of the button. I'm then doing some calculation to center the text.
This produces this when the text is set to 'Test':
And when i enter this piece of code below the first DrawString:
sb.DrawString(font, "test", new Vector2(500, 50), Color.Pink);
I should mention that that grey square is being drawn in the same spritebatch, before the button and the text.
Any ideas as to what could be causing this? I have a feeling it may be due to draw order, but i have no idea how to control that.