This chapter is from the book
Q&A
- Q. What if I want to use a custom TrueType font (.ttf) file that I really like in my game?
- A. You can include the font file in the project directory and XNA will look for it when you try to load it with Content.Load(). Just be careful not to distribute any nonlicensed font files with your game. The fonts included with XNA are free, but not all font files are public domain. Many of the Windows fonts (such as Times New Roman) are licensed and cannot be distributed with a game.
- Q. How can I print a message that’s centered on the screen?
- A. Take a look at the SpriteFont.MeasureString() method, which returns a Vector2 containing the dimensions of the string that you can use to center the text based on the width and height of the screen and the text.