1
\$\begingroup\$

I'm planning on my game using multiple backgrounds so I'm trying to use spritefonts to draw the text. Every time I load my spritefont I get a error.

Line1 = content.Load<SpriteFont>("Courier New");
Line2 = content.Load<SpriteFont>("Courier New");

This is the error I get.

Error loading "Courier New". File not found.

Although this was the font listed on the official microsoft website http://msdn.microsoft.com/en-us/library/bb447673.aspx.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Have you actually imported the font into your project through visual studio? \$\endgroup\$
    – ssb
    Commented Nov 10, 2012 at 13:15
  • \$\begingroup\$ try this , its a msdn tutorial to load and using the spritefont . pls check this too if u r begineer msdn.microsoft.com/en-us/library/bb447673.aspx \$\endgroup\$
    – Eldho
    Commented May 29, 2013 at 14:27

2 Answers 2

7
\$\begingroup\$

You have to add new a new SpriteFont item to your content project. Inside the .spritefont file, there is FontName element. Replace the default value with Courier New.

Take note of the asset name of the .spritefont file you added. Because that is the name you should reference inside your game. Assuming you named the asset as courier, you could load the font like this

SpriteFont Line1 = content.Load<SpriteFont>("courier");
\$\endgroup\$
3
\$\begingroup\$

You can only load content that's in your Content project. Since there isn't any file with the name "Courier New" (.ttf, or whatever) in your Content project, it's natural you'd get a File not found error.

You can't just load system fonts. The example in the official Microsoft website just needed an example font name. For their situation to work, they'd need a "Courier New.ttf" (or something) in the corresponding Content project.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .