简体   繁体   English

如何将用户生成的png图像加载为纹理(而不是xnb)?

[英]How to load user generated png images as textures (not xnb's)?

The idea is to let users create their own textures, put them in a folder as images (and maybe set some properties in a separate text file) for the game to load and work accordingly. 我们的想法是让用户创建自己的纹理,将它们作为图像放在文件夹中(也可以在单独的文本文件中设置一些属性),以便游戏加载和工作。

Usually I have my own textures as images, they are processed by Visual Studio when compiling, and then the game uses XNB files. 通常我将自己的纹理作为图像,在编译时由Visual Studio处理,然后游戏使用XNB文件。 But how about end users that don't have VS installed? 但是没有安装VS的最终用户怎么样?

UPD: The only safe option (that doesn't require manual resource disposal) seems to be replacing the original resource files in XNB format. UPD:唯一安全的选项(不需要手动资源处理)似乎正在替换XNB格式的原始资源文件。 For that, you can process your own PNG, WAV and other files with this tool from codeplex and put them in content folder of the game. 为此,您可以使用this tool from codeplex处理您自己的PNG,WAV和其他文件,并将它们放在游戏的内容文件夹中。

if you works in windows only... (not xbox and not windows phone) 如果你只在Windows工作...(不是xbox而不是Windows手机)

you can use Texture2d.FromStream(File.OpenRead(path)); 你可以使用Texture2d.FromStream(File.OpenRead(path));

You have to realize that this way, you should call the texture dispose method when the texture is not needed to free resources. 你必须意识到这一点,你应该在不需要纹理来释放资源时调用纹理dispose方法。

Wehn you use the content manager, is the manager who call the method when the game ends. 我们使用内容管理器,是游戏结束时调用该方法的管理员。

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

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