How to create and immediately be able to use spritefonts during runtime?

657 views Asked by At

I'd like to know if it is possible to select a typeface, font size and be able to use it right away during runtime in an XNA application.

If it isn't possible using built-in runtime methods, maybe it's easier (or better, or faster) to do it using some automation software (like autoit) to create spritefont file in the background, and be able to use it afterwards in an XNA app without restarting the app?

I'm going to use this mainly on my own computer for testing and picking fonts, so I'm okay if it requires full VS installation along with XNA framework and any other stuff.

1

There are 1 answers

1
Rocket3G On

Easy put, it can be done, but you have to use WinForms, link to tutorial in order to load spritefonts. You could do it simpler, by making a couple of spritefonts before you do anything (or create spritefonts for every font you have and add them to the content). This is so, because of how XNA handles spritefonts. As you've seen, SpriteFonts are basically an xml file. This is not how the final binaries are. The final binaries are images containing every character in the font you selected at that size. That way, the gamer doesn't have to have the font installed in order to play your game, and therefore you can do some awesome stuff with fonts and the user can't use that font (unless he rips it).

I have not yet found a tutorial for winforms and spritefonts, but I suppose that the model version needs only a little modification for it to work with spritefonts.