Can't get content to load using Monogame with VS2012

NibblyPig picture NibblyPig · Jan 24, 2013 · Viewed 11.7k times · Source

My code is

new GameFont(Content.Load<SpriteFont>("LoadingFont"), "LoadingFont")

According to what I've read, you have to use VS2010 to compile your assets into .xnb format, which I have done, and place them into the Content subfolder in your bin directory, which I have also done. However, I get an error saying "Could not load LoadingFont asset!".

I'm not really sure what else to do. I read a very old post saying that assets made using XNA 4 won't work, but I don't know if that's still true, or how to change my version of XNA to 3.1.

Any ideas? Perhaps there's a better way without using VS2010 at all?

Answer

craftworkgames picture craftworkgames · Jan 25, 2013

Have you added the content to the Content folder of your project and set the Build Action to Content (in the properties window).

I'm not exactly sure what the process is to use assets in the .xnb format. I know it can be done that way but I normally just add the raw image and sounds files to my Content folder directly. Font's might be a little trickier to do that way though.

EDIT: 2015

A lot of things have changed since this question was written. These days MonoGame has it's own Pipeline tool for processing content into XNB files. The first thing to try would be to process your SpriteFont using the new Pipeline. This way you can avoid the need to depend on XNA altogether.

Alternately, another way to get around font issues in MonoGame is to pre-render them to a texture using the BMFont tool and use MonoGame.Extended to render them in your game.

Once you've installed MonoGame.Extended you can load fonts created with BMFont just as you would a SpriteFont but using the BitmapFont class instead.

_bitmapFont = Content.Load<BitmapFont>("my-font");

Then render some text like so:

 _spriteBatch.Begin();
 _spriteBatch.DrawString(_bitmapFont, "Hello World", new Vector2(100, 200), Color.Red);
 _spriteBatch.End();

I have a full tutorial on my blog