Delta Engine Blog

All about multiplatform and game development

Versatile Bitmapfonts

The last couple of weeks i have worked (on and off) on a system that implements .TTF fonts as bitmap (one to several .png files, depending on the font size) including an .xml file for info on character kerning and texture coordinates, so it can be used on any platform without being dependant on ttf support.

To generate a new font, you simply have to pass the font name (the .TTF font must exist in your system for the generation only), and the desired size.

 

Font Arial = new Font("Arial", 12.5f);

 

The font can then be rendered in any color, anywhere on screen.

Arial.Write(120, 20, "Text");
Arial.WriteCentered(250, 120, "Text is a nice text");

The latter function centers the text around the point given.

The latest addition i made is rotated text, so it works on either portrait or landscape layout.

Arial.Write(120, 20, "Text", 90);

However, the rotation can be anywhere between 0 and 360 degree.

 

Currently, each character is drawn dynamically, but it is planned to add a render to texture function, so we can draw static strings as a single sprite.

 

Of course, this is actually animated, rotating like it never could before.