我正在 MonoGame 中使用 Open GL 制作太空入侵者游戏,我正在尝试加载我已添加到内容文件夹的纹理(它是一个名为“Invader”的 PNG 文件)
我使用的代码是:
invader = Content.Load<Texture2D>("Invader");
但是当我尝试运行它时它说:
ContentLoadException was unhandled
could not load Invader as a non-content file!
最佳答案
I am trying to load a texture that I have added to the Content folder (It is a PNG file called "Invader") invader = Content.Load("Invader");
实际上,你可以像这样直接加载已经添加到Content文件夹中的PNG内容:
invader = Content.Load<Texture2D>("Invader");
请注意,在某些平台上,文件名是区分大小写的,因此请注意确保它完全匹配。此外,请确保您已在“属性”窗口中将文件设置为内容/复制(如果较新)。
另一种方法是使用 XNA Game Studio Content Pipeline 将您的 Assets 编译成优化的二进制 XNB 文件。或 MonoGame Content Pipeline .这将为您提供更好的性能,但会带来额外的开发开销。
我还应该提到,当将 Sprite 渲染为原始 PNG 文件时,您应该使用 BlendState.NonPremultiplied在调用 SpriteBatch.Begin以获得最佳效果。我在我的游戏中已经这样做了一段时间,我对结果非常满意。
关于C# MonoGame 帮助? (Content.Load<Texture2D> ("Invader");),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17953880/