简体   繁体   English

无法使用带有VS2012的Monogame加载内容

[英]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. 根据我所读到的,您必须使用VS2010将您的资产编译为.xnb格式,我已经完成了,并将它们放入bin目录中的Content子文件夹,我也做过。 However, I get an error saying "Could not load LoadingFont asset!". 但是,我收到错误消息“无法加载LoadingFont资产!”。

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. 我读了一篇很老的帖子说使用XNA 4制作的资产不起作用,但我不知道是否仍然如此,或者如何将我的XNA版本更改为3.1。

Any ideas? 有任何想法吗? Perhaps there's a better way without using VS2010 at all? 也许没有使用VS2010会有更好的方法吗?

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. 我不确定使用.xnb格式的资产的过程是什么。 I know it can be done that way but I normally just add the raw image and sounds files to my Content folder directly. 我知道它可以这样做但我通常只是将原始图像和声音文件直接添加到我的Content文件夹中。 Font's might be a little trickier to do that way though. 尽管如此,Font可能会有点棘手。

EDIT: 2015 编辑: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. 如今,MonoGame拥有自己的Pipeline工具 ,可以将内容处理成XNB文件。 The first thing to try would be to process your SpriteFont using the new Pipeline. 首先要尝试的是使用新的Pipeline处理你的SpriteFont This way you can avoid the need to depend on XNA altogether. 这样就可以避免完全依赖XNA。

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. 或者,另一种解决MonoGame中字体问题的方法是使用BMFont工具将它们预渲染为纹理,并使用MonoGame.Extended在游戏中渲染它们。

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. 一旦你安装了MonoGame.Extended ,就可以加载使用BMFont创建的字体,就像使用SpriteFont但是使用BitmapFont类。

_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; 我一直在VS2012中使用MonoGame而没有遇到麻烦; Content.Load<T>("myContent") still works for me. Content.Load<T>("myContent")仍适用于我。 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. 就像@craftworkgames一样,我不能给你一个完整的答案。 But the traditional Content Pipeline that came with XNA 3.1 has gone in 4. So any assets need loading a slightly different way. 但XNA 3.1附带的传统内容管道已经进入4中。因此任何资产都需要加载略有不同的方式。 For example, to load a .png asset to display a sprite I do the following: 例如,要加载.png资源以显示精灵,我会执行以下操作:

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

and add the .png file to the solution as normal. 并正常将.png文件添加到解决方案中。 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. 单击“Content”文件夹下的Monogame Content Pipeline。

Add in your spritefont or texture. 添加你的spritefont或纹理。

Make sure in the Monogame Content Pipeline that you change the action from "Build" to "Copy" 确保在Monogame Content Pipeline中将操作从“Build”更改为“Copy”

Then when you want to load the content simply; 然后当你想简单地加载内容时; texture = content.Load("texture.png"); 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. 我有类似的问题,但“Windows 8商店”作为目标平台......虽然Windows Open GL版本的一切都很好。 On Windows 8 I received "could not load as a non-content file" when I tried content.Load("Fonts/TestFont"). 在Windows 8上,当我尝试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. 我使用MonoGame.Windows8项目替换了我的解决方案中的MonoGame DLL(我从CodePlex下载了源代码)并进行了一些调试...并发现MonoGame在bin ... \\ Debug \\ AppX文件夹中查找Content文件夹...在构建期间,Content文件夹被复制到不同的位置。 So when I manually copied the Content folder into AppX folder, the error has gone and my game prototype works fine now. 因此,当我手动将Content文件夹复制到AppX文件夹时,错误已经消失,我的游戏原型现在正常工作。

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. 我想我或者错过了与AppX相关的项目首选项中的一些设置(可能是Windows 8设备模拟器需要这个文件夹?)或者...... MonoGame应该在不同的地方寻找内容文件夹...无论如何我会更新现在手动编辑内容文件夹,因为它在编译期间被复制到错误的位置。

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. 我的项目中有Content文件夹并且构建操作设置正确(内容)...并且选择了'复制始终'但在构建(compliation)期间将Content文件夹复制到Debug文件夹,同时应将其复制到Debug \\ AppX文件夹,否则MonoGame找不到它。 (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. 也许这只是我的Visual Studio 2012中的一些配置问题。

Hope this information helps. 希望这些信息有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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