Simple static class that will write out a message that is passed in. The SpriteSheet is 256x256 and the A-Z starts at line 240 and the 0-9 starts at 248. Each character is 8x8. I hate the if (ix >= 32) and wondered if there is a tidier way of doing this? I'm pleased it's only one Draw call, but it looks ugly.
public static class Font
{
private static String chars = "" + //
"ABCDEFGHIJKLMNOPQRSTUVWXYZ " + //
"0123456789.,!?'\"-+=/\\%()<>:; " + //
"";
public static void Draw(string msg, SpriteSheet sprites, SpriteBatch spriteBatch, int x, int y, Color color)
{
msg = msg.ToUpper();
for (int i = 0; i < msg.Length; i++)
{
int ix = chars.IndexOf(msg[i]);
int w = 0, h = 240;
if (ix >= 0)
{
if (ix >= 32)
{
w = 32;
h = 248;
}
spriteBatch.Draw(sprites.Sheet, new Rectangle(x + i * 8, y, 8, 8), new Rectangle((ix - w) * 8, h, 8, 8), color);
}
}
}
}