C#MonoGame帮助? (Content.Load&所述;的Texture2D>(QUOT;入侵者&QUOT)) [英] C# MonoGame Help? (Content.Load<Texture2D>("Invader");)

查看:237
本文介绍了C#MonoGame帮助? (Content.Load&所述;的Texture2D>(QUOT;入侵者&QUOT))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MonoGame利用Open GL制作一个太空侵略者游戏,我试图加载,我已经加入到内容文件夹纹理(它被称为侵略者的PNG文件)结果
中的我使用的代码是:

 侵略者= Content.Load<&的Texture2D GT(侵略者); 



然而,当我尝试运行它,它说:




ContentLoadException是未处理的结果无法加载侵略者为
非内容文件!



解决方案

我试图加载我已经添加到内容文件夹纹理(它被称为侵略者的PNG文件)
入侵者= Content.Load(侵略者);




其实,你可以加载已添加到该PNG内容内容文件夹直接像这样:

 侵略者= Content.Load<&的Texture2D GT(侵略者); 

请注意,该文件名的的在某些平台上的情况下senitive所以要小心它完全匹配。此外,请确保您所设置的文件内容/复制如果在属性窗口中更新。



另一种方法是编译你的资产注入采用优化的二进制文件XNB 的XNA Game Studio内容管线或的 MonoGame内容管道。这会给你更好的性能,但携带额外的开发开销



我应该还提到,渲染你的精灵为原料的PNG文件时,你应该使用的 BlendState.NonPremultiplied 在调用的 SpriteBatch.Begin 获得最好的结果。我一直在这样做,在我的游戏了一段时间,我对结果非常满意。


I am Making a Space Invaders Game using Open GL in MonoGame and I am trying to load a texture that I have added to the Content folder (It is a PNG file called "Invader")
The code that I use is:

invader = Content.Load<Texture2D>("Invader");

However when I attempt to run it It says:

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

Actually, you can load the PNG content that has been added to the Content folder directly like so:

invader = Content.Load<Texture2D>("Invader");

Note that the filename is case senitive on some platforms so be careful that it matches exactly. Also, make sure you've set the file to Content / Copy if newer in the Properties window.

The alternative is to compile your assets into optimized binary XNB files using the XNA Game Studio Content Pipeline or the MonoGame Content Pipeline. This will give you better performance but carries extra development overhead.

I should also mention that when rendering your sprites as raw PNG files you should use BlendState.NonPremultiplied in the call to SpriteBatch.Begin for best results. I've been doing it this way in my games for a while and I'm pretty happy with the results.

这篇关于C#MonoGame帮助? (Content.Load&所述;的Texture2D&GT;(QUOT;入侵者&QUOT))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆