在 C# 中实时绘制变量以进行调试

发布于 2024-12-03 01:48:17 字数 443 浏览 0 评论 0 原文

我正在使用 XNA 开发 C# 项目。如果有一种方法可以在游戏运行时实时绘制某些变量的值,将会非常有用。 (只是为了调试,我不想在最终项目中使用图表。)

这似乎以前可能已经做过,但我找不到除此之外的任何内容:

http://devmag.org.za/2011/02/09/using-graphs-to-debug-physicals-ai-and-animation-efficiently/

我愿意写我自己的系统或使用别人的系统。如果有一个现有的已发布项目,我想找到它,这样我就不必重新发明轮子。如果不是,处理这个问题的最佳方法是什么?

谢谢!

I'm working on a project in C# using XNA. It would be useful to have a way to graph the value of certain variables in real time as the game is running. (Just for debugging, I don't want the graphs in the final project.)

This seems like something that has probably been done before, but I can't find anything other than this:

http://devmag.org.za/2011/02/09/using-graphs-to-debug-physics-ai-and-animation-effectively/

I'm willing to write my own system or use someone else's. If there is an existing released project, I'd like to find it so I don't have to reinvent the wheel. If not, what;s the best way to handle this?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫瑾少女 2024-12-10 01:48:17

您可能可以使用 XNA 编写一个非常简单的系统。

您应该有一些非常基本的东西来绘制线条:

public void DrawLine(Point first, Point second);

在每一帧上运行这个系统来收集变量的值。跟踪以前的值。

在先前值和当前值之间画一条线。

如果采样频率足够高,您可以获得像这样的看起来相当不错的图表。

You could probably write a pretty easy system using XNA.

You should have something very basic for plotting lines:

public void DrawLine(Point first, Point second);

Run this system on every frame to collect the variable's value. Keep track of previous value.

Draw a line between previous value to current value.

If the sampling frequency is high enough, you can get a pretty decent looking graph like this.

风情万种。 2024-12-10 01:48:17

您可以将要检查的值写入 csv 文件,然后使用 Excel 绘制图表。 这是关于用 C# 编写 csv 文件编写器/解析器的教程。

XNA 不支持直接在屏幕上绘制单行/像素(需要通过 SpriteBatch)。我唯一能想到的就是使用texture2D并在其上绘制图形的像素。不过,你必须将纹理保持在镜头前,并使用一些我实际上不太了解的奇怪矩阵魔法。 :P

You could write the values you want to check in a csv file, then draw a graph with excel. Here's a tutorial on writing a csv file writer/parser in C#.

The XNA hasn't support for drawing single line/pixels to screen directly (need to pass through a SpriteBatch). The only thing else I can imagine of is using a texture2D and draw your graph's pixels on it. You'll have to keep the texture in front of the camera though, with some strange matrix magics of which I don't actually know much. :P

情归归情 2024-12-10 01:48:17

Xen图形API具有此功能。它似乎适用于某些内置变量,例如 FPS,但它都是开源的,因此我怀疑添加您自己的图表会很容易: http://xen.codeplex.com/

编辑

我刚刚记得Farseer物理也有代码来做到这一点http://farseerphysicals.codeplex.com/。它可能比 Xen 图更容易撕掉。

The Xen graphics API has this feature. It appears to be for some built in variables, such as FPS, but it's all open source so I suspect it will be easy to add graphs of your own: http://xen.codeplex.com/

EDIT

I just remembered that Farseer physics also has code to do this http://farseerphysics.codeplex.com/. It's probably easier to rip out than the Xen graphs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文