Time for action – add SpriteFonts to Game1
Right click on the
Fonts
folder in the Content project in Solution Explorer and select Add | New Item.From the Add New Item dialog, select Sprite Font.
Name the font Pericles36.spritefont. After adding the font, the
spritefont
file will open in the editor window.In the
spritefont
file, change<Fontname>Kootenay</Fontname>
to<Fontname>Pericles</Fontname>
.Change
<Size>14</Size>
to<Size>36</Size>
.Add the following declaration to the Game1 class:
SpriteFont pericles36Font;
Update the
LoadContent()
method of the Game1 class to loadspritefont
by adding:pericles36Font = Content.Load<SpriteFont>(@"Fonts\Pericles36");
What just happened?
Adding a SpriteFont to your game is very similar to adding a texture image. Since both are managed by the Content Pipeline, working with them is identical from a code standpoint. In fact, SpriteFonts are really just specialized sprite sheets, similar to what we used for...