简体   繁体   中英

Can't get content to load using Monogame with VS2012

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?

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

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.

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 ;)

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 :)

I had similar problem but with 'Windows 8 Store' as a target platform... while everything was fine with Windows Open GL version. On Windows 8 I received "could not load as a non-content file" when I tried content.Load("Fonts/TestFont").

I replaced MonoGame DLLs in my solution with the MonoGame.Windows8 project (I downloaded the sources from CodePlex) and I did some debugging... and found out that MonoGame looks for the Content folder in the bin...\\Debug\\AppX folder... while during the build the Content folder is copied into different place. So when I manually copied the Content folder into AppX folder, the error has gone and my game prototype works fine now.

I guess I either missed some setting in the Project preferences related to AppX (Presumably this folder is needed for the Windows 8 device emulator?) or... MonoGame should look for the Content folder in different place... Anyway I will be renewing the Content folder manually for now because it is copied into wrong place during the compilation.

I have Content folder in my project and build action is set correctly (Content)... and 'Copy always' is chosen but during the build (compliation) that Content folder is copied to Debug folder while it should be copied to Debug\\AppX folder otherwise MonoGame can't find it. (I maybe wrong with exact paths because I am currently at work and the issue is at my home PC)

Maybe it is just some configuration issue in my Visual Studio 2012.

Hope this information helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM