本文介绍了纹理不在我的XNA游戏应用中显示。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 今天,我重新开始编写我的第一个视频游戏。我在一年前开始这个项目,但很快就休息了一下,以便更清楚地思考我的设计方法。但是,在修复某些内容并清理我的代码时,我偶然发现了一个关键的运行时错误。问题是XNA框架,我正在使用的库集,可以在Game类中使用Draw()函数时绘制我的游戏对象的纹理。当我尝试在Game类中使用对SpriteBatch对象的引用并开始从外部类绘制纹理时,情况并非如此。结果,我现在拥有一个没有角色的2D世界。我仍然可以触发一些函数,但就好像它是一个字符。这是一个片段:Today, I got back into coding my first video game. I had started this project a year ago, but took a break soon after to think more clearly about my design approach. However, while fixing some stuff and cleaning my code, I stumble upon a critical runtime bug. The problem is that the XNA framework, which is the library set I''m using, can draw the textures of my game objects when using the Draw() function inside the Game class. This is not true when I tried using a reference to the SpriteBatch object inside the Game class and begin drawing textures from an external class. As a result, I now have a 2D world without the characters. I can still trigger some functions, but it is as if it was aghost character. Here''s a snippet: 展开 | 选择 | Wrap | 行号推荐答案嗯这很奇怪,我做你正在尝试的一直这么做。将sprite批处理传递给另一个类并用它来绘制。 你能否验证纹理本身是否有效?也许发生了什么事,但它没有正确加载?你会认为你会得到一个例外,但也许它正在绘制,只是得到一个空白的图像?实际上你确实说它在你的游戏课上有效... 你能发一些更完整的代码吗?我知道这是有效的,因为我一直这样做,所以也许其他一些有趣的东西正在发生。我只需要查看您的源代码来帮助您调试它。Hmm this is strange, I do what you are trying to do all the time. Pass the sprite batch along to another class and use it to draw.Can you please verify the texture itself is valid? Maybe something happened and it''s not loading correctly? You''d think you''d get an exception, but maybe it''s drawing and just getting a blank image? Actually you did say it worked in your game class...Can you please post some more complete code? I know this works because I do it all the time, so maybe something else funny is going on. I just need to see your source to help you debug it.感谢您的快速回复。我将仔细检查可以在Game类中绘制目标纹理。当我今天应用一些新的压缩设置时,我将测试的特定纹理可能变得混乱。我会尽快回复。Thanks for the quick reply. I will double check that the target texture can be drawn in the Game class. The particular texture I will be testing could have gotten messy when I applied some new compression settings today. I''ll post back as soon as possible.纹理实际上是在游戏中完成的。我包含了两个有问题的文件,但由于它比最大上传空间大,所以无法包含整个项目。The texture actually draws when done inside Game. I included the two files in question, but could not include the whole project since it was bigger than the maximum upload space. 附加文件 partial_source.zip (8.6 KB,63 views) Attached Files partial_source.zip (8.6 KB, 63 views) 这篇关于纹理不在我的XNA游戏应用中显示。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-02 15:45