Text effects in MonoGame and XNA

Play Game text in MonoGame game

In MonoGame you can load a SpriteFont in an XNB file created using the XNA Content Pipeline. You can then write text using SpriteBatch.DrawString. If you want to add effects to your text, there is no way to do this using just the DrawString method. There is a way however to create a SpriteFont that has effects built into this.

There are two ways of building a font using the XNA Content Pipeline. The first way is using a Sprite Font Description. This uses an XML file and is an easy to compile a Sprite Font from a font on you computer. This is easy to make changes to, but it won't help us here. The second way is using a Sprite Font Texture.

A Sprite Font Texture looks like this:

Sprite Font Texture

This is an image that you import in the XNA Content Pipeline using Sprite Font Texture as the Content Processor and Texture as the Content Importer. You can then use the generated XNB file as a normal Sprite Font.

The best tool I've found for creating these is Sprite Font 2. This lets you add a number of effects to your font. As a Sprite Font Texture is a PNG file, you can also edit it more yourself.

No Comments