Can't get content to load using Monogame with VS2012

11,864

Solution 1

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

Solution 2

I've been using MonoGame in VS2012 with no trouble; Content.Load<T>("myContent") still works for me. One thing that has been catching me out lately (tip: don't code when sleep-deprived) is that you have to check your assets are set to "Copy to output directory" in Solution Explorer, or else when the game builds, the assets won't go with it, which is why you get that error - it can't load what isn't there! Right-click on your assets and look under Properties. If they're set to "Do not copy" then you'll want to change that.

Solution 3

Like @craftworkgames I can't give you a full answer. But the traditional Content Pipeline that came with XNA 3.1 has gone in 4. So any assets need loading a slightly different way. For example, to load a .png asset to display a sprite I do the following:

rock = Texture2D.FromStream(GraphicsDevice, TitleContainer.OpenStream(@"Rock-Large-Stones-PT.png"));

and add the .png file to the solution as normal. I'm pretty sure it's going to be something similar for fonts but I haven't quite figured it out yet either ;)

Solution 4

I was having the same issue not sure if you got it resolved or not but here is what I did.

Click on the Monogame Content Pipeline under the "Content" folder.

Add in your spritefont or texture.

Make sure in the Monogame Content Pipeline that you change the action from "Build" to "Copy"

Then when you want to load the content simply; texture = content.Load("texture.png");

Hope this helps :)

Share:
11,864
NibblyPig
Author by

NibblyPig

Hello!

Updated on June 07, 2022

Comments

  • NibblyPig
    NibblyPig almost 2 years

    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?

  • NibblyPig
    NibblyPig about 11 years
    This is pretty much it. Apparently they changed how to do it in one version of Monogame from just having to be in /bin/content to actually having to be in the solution. Adding it to the solution fixed it :)
  • nathanchere
    nathanchere about 11 years
    That's all very well when developing for Windows but won't work for other platforms (eg Android, IOS, Win8)
  • Mastro
    Mastro over 10 years
    Setting the Build Copy property on the file itself to "Copy if Newer", worked for me.
  • BjarkeCK
    BjarkeCK over 10 years
    All i needed to hear was "tip: don't code when sleep-deprived" and then it hit me^^ Thanks!
  • craftworkgames
    craftworkgames over 8 years
    @ashes999 I updated the link to one that works. Things have changed a bit since 2013 when this question was asked.
  • craftworkgames
    craftworkgames over 8 years
    @ashes999 in my defense I updated the link from my phone and I haven't written a link only answer for years. Going back and updating all my old answers would be pretty time consuming, but I'm happy to do it as they come up. I've added more detail to this one, hopefully without loosing the context of the original answer.
  • ashes999
    ashes999 over 8 years
    @craftworkgames no worries. Your answer (here) ranks highly on google, and you have lots of rep, so I figured this specific case would benefit from more details. Cheers.