Game Development Reference
In-Depth Information
is a CharacterData class that has information about the character and how
the sprite will be used.
public class CharacterSprite
{
public Sprite Sprite {get; set;}
public CharacterData Data { get; set; }
public CharacterSprite(Sprite sprite, CharacterData data)
{
Data = data;
Sprite = sprite;
}
}
The Text class is a list of CharacterSprites . It is also responsible for or-
dering the letters. Given a simple text string, it creates a CharacterSprite for
each character and orders them one after the other. It also handles the correct
offsets. Here is the code.
public class Text
{
Font _font;
List<CharacterSprite> _bitmapText = new List<CharacterSprite>();
string _text;
public List<CharacterSprite> CharacterSprites
{
get { return _bitmapText; }
}
public Text(string text, Font font)
{
_text = text;
_font = font;
CreateText(0, 0);
}
private void CreateText(double x, double y)
{
_bitmapText.Clear();
double currentX = x;
double currentY = y;
foreach (char c in _text)
{
CharacterSprite sprite = _font.CreateSprite(c);
 
Search WWH ::




Custom Search