Xna调试
我使用 console.out.writeline() 打印属于 XNA 游戏中不同精灵的坐标。 但几秒钟后,游戏开始变得非常慢,几乎停止。
(不写入控制台时,性能没有问题)。 (精灵的位置在每个更新方法中都被写入)
有没有一种方法可以在不破坏游戏性能的情况下写入控制台?
I use the console.out.writeline() to print the coordinates belonging to the different sprites in a XNA game. But after a few seconds, the game starts to go really slow, and almost stop.
(When not writing to the console, there are no problems with performance).
(The sprite's positions are written in every update method)
Is there a way to write to the console without destroying the performance to the game?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以写入日志文件而不是控制台吗? 由于缓冲和缺乏滚动、显示等,这可能会更快。
在运行时,您实际上有一个控制台吗? 如果是这样,请在不感兴趣时尝试将其最小化。 我的猜测是滚动导致了问题。
编辑:好的,似乎有一些证据是正确的。
一些测试...我没有安装 XNA,但写入控制台的不同方式仍然很有趣。 我将数字 0-99999 写入各种控制台:
因此,如您所见, Visual Studio 控制台非常慢,非最小化的“普通”控制台是第二慢的,最小化的控制台相当慢,并且写入文件非常快。
我坚持我的建议,尝试写入文件而不是控制台,否则,如果它是独立控制台,请尝试在大多数情况下将其最小化。
Are you able to write to a log file instead of the console? That may well be faster due to buffering and the lack of scrolling, displaying etc.
Do you actually have a console up while this is running? If so, try minimising it when you're not interested. My guess is it's the scrolling which is causing the problem.
EDIT: Okay, it seems some evidence is in order.
A few tests... I don't have XNA installed, but different ways of writing to consoles are still interesting. I wrote the numbers 0-99999 to various consoles:
So as you can see, the Visual Studio console is painfully slow, a non-minimised "normal" console is next slowest, a minimised console is reasonably nippy, and writing to a file is very quick.
I stand by my advice to try writing to a file instead of the console, and otherwise if it's a standalone console, try to minimise it for most of the time.
“有没有一种方法可以在不破坏游戏性能的情况下写入控制台?”
好吧,您可以像大多数游戏引擎(最著名的是 Quake)一样创建自己的游戏控制台,并在按下按键时显示控制台。
编辑:
如果您不想实现自己的控制台,有一个项目可以执行此操作:
http://www .codeplex.com/XnaConsole
比 Win32 控制台有优势,因为它在游戏中以游戏帧速率运行,并且在控制台和 xna 应用程序之间切换时不会让您丢失设备。 (尽管在 XNA 中设备恢复是自动的,但丢失设备仍然会在幕后发生)
"Is there a way to write to the console without destroying the performance to the game?"
Well, you could create your own ingame console like most game engines do (most notably Quake), and display the console when a key is pressed.
Edit:
if you don't want to implement your own console, there is a project doing this:
http://www.codeplex.com/XnaConsole
which has advantages over the Win32 console, because it runs in game, at game framerate, and won't make you loose your device when switching between the console and your xna app. (Although device recovery is automatic in XNA, loosing the device still happens under the covers)
您可能向控制台写入了太多数据。 使用计数器或计时器减少控制台写入的频率。 每秒一次更新通常足以满足您的需求。
It is likely that you are writing too much data to the console. Reduce the frequency of console writes by using a counter or a timer. One update per second is usually enough to see what you need.
我知道这是一篇旧文章,但对于那些有类似问题的人来说,有更好的方法。 您可以包含另一个控制台类型的库,它非常易于使用(比 xna 控制台项目容易得多)。 它称为 XNA 调试终端,可以在 http://www.protohacks.net/xna_debug_terminal
这会在游戏顶部放置一个类似命令窗口的终端,并允许您查看/设置任何变量的值、调用任何方法,甚至实时观察值的变化。 它是完全开源的,可与 XNA 3.0 和 XNA 3.1 配合使用。 这可以让您在游戏执行期间随时轻松查看精灵坐标(或其他任何内容)。
I know this is an old post, but for those with similar questions there is a better way. There is another console-type library you can include that is really easy to use (a lot easier than the xna console project). It is called XNA Debug Terminal and it can be found at http://www.protohacks.net/xna_debug_terminal
This puts a terminal like command window on top of your game and allows you to view/set the value of any variable, invoke any method, or even watch values change in real time. It is completely open source and works with XNA 3.0 and XNA 3.1. This can easily allow you to see your sprite coordinates (or anything else) at any time during your game execution.
简单地说,您可以执行以下操作:
创建一个名为
Trace
的类,并在绘制方法中使用SpriteBatch.DrawString(...)
在屏幕上绘制所需的信息。 code> 我猜这比控制台更好..我希望这有帮助,
和平。
Simply,you can do the following:
Create a class called e.g.
Trace
, and in the draw method you draw the information you need on the screen usingSpriteBatch.DrawString(...)
this is better than Console I guess ..I hope this helps,
Peace.