public Texture2D this[ImageDescriptor index] { get { if(!_imageTable.ContainsKey(index)) { Pattern pattern = _patternTable[index.Pattern].Value; Color foreground = _colorTable[index.Foreground].Value; Color background = _colorTable[index.Background].Value; Texture2D texture = new Texture2D(_graphicsDevice, pattern.Columns, pattern.Data.Length); Color[] data = new Color[pattern.Columns * pattern.Data.Length]; for(int y=0;y<pattern.Data.Length;++y) { for(int x=0;x<pattern.Columns;++x) { data[x + y * pattern.Columns] = ((pattern.Data[y] & ((uint)(1 << x))) > 0) ? foreground : background; } } texture.SetData(data); _imageTable[index] = texture; } return _imageTable[index]; } }
public void RenderText(string text, int x, int y, string foreground, string background) { ImageDescriptor descriptor = new ImageDescriptor(null, foreground, background); Encoding.ASCII.GetBytes(text) .Select(c=>string.Format("character{0}",c)) .ToList() .ForEach(imageName=> { descriptor.Pattern = imageName; var texture = _images[descriptor]; _spriteBatch.Draw(texture, new Rectangle(x, y, texture.Width, texture.Height), Color.White); x += texture.Width; }); }