using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; namespace GameName1 { static class Font { static public Dictionary Letters; static public Texture2D Texture; //const int charWidth = 53; //const int charHeight = 51; const int charWidth = 55; const int charHeight = 62; const float halfCharWidth = charWidth / 2; const float halfCharHeight = charHeight / 2; const int rows = 9; const int columns = 10; const int spaceSize = 18;//18 pixel word space static public void Initialize() { Letters = new Dictionary(35); String charSequence = "*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz!\"#$%&'()"; for (int i = 0; i < rows; i++) for (int j = 0; j < columns; j++) Letters[charSequence[i * columns + j]] = new Rectangle(j * charWidth, i * charHeight, charHeight, charWidth); } static public void DrawString(SpriteBatch spriteBatch, String str, float size, Vector2 position, Color color) { for (int i = 0; i < str.Length; i++) { if (str[i] != ' ') { position += new Vector2(size * halfCharWidth, 0); try { spriteBatch.Draw(Texture, position, Letters[str[i]], color, 0f, new Vector2(halfCharWidth, halfCharHeight), size, SpriteEffects.None, 0f); } catch { Console.WriteLine("Character not found in FontSprite."); } } else position += new Vector2(spaceSize * size, 0); } } } }