有没有比使用 Console.Clear() 更好的方法来制作控制台游戏?
我正在摆弄游戏循环并创建一些游戏作为练习。
目前,我有一个稳定的游戏循环,其中游戏更新得尽可能快,渲染每秒更新 x 次(当前为 25 次)
渲染方法基本上是绘制 + Console.Clear() ,并且在非常高的情况下更新显示变得非常紧张,因为当 Console.Clear() 命中时它还没有完成绘制。
有没有更好的方法来做这样的事情?
我可以将任何数据写入控制台,然后用其他数据替换它吗?
I'm messing around with game loops and going to create some games as practice.
Currently I have a steady game loop up where the game is updated as fast as possible and the rendering is updated x times a second (25 currently)
The rendinging method is basically a draw + Console.Clear() and at very high updates the display becomes very jittery since it's not finished drawing when Console.Clear() hits.
Is there a better way of doing something like this?
Can I write whatever data to the console and then replace it with some other data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于您无论如何都使用 C#,因此您可能需要研究 XNA Framework< /a>.
我猜你的问题是由于
Console.Clear()
没有针对这种使用进行优化,因为 XNA 使用类似的方法(Clear()
在GraphicsDevice
)。如果您不想尝试使用 XNA,那么绘制一个矩形(纯黑色或灰色或其他)可能比调用 Clear() 来“清空”屏幕和然后在它上面画图。
Since you're in C# anyway, you might want to look into the XNA Framework.
I'm guessing your problem arises from
Console.Clear()
not being optimized for this kind of use, as XNA uses a similar method (Clear()
is called on aGraphicsDevice
).If you don't want to try using XNA, then it may possibly be faster to draw a rectangle (solid black or gray or whatever) rather than call
Clear()
to 'blank' out the screen and then draw over it.您可能想查看 ConsoleLibrary
我没有使用它,但来自文章/演示似乎可以让您在控制台上做很多巧妙的事情。
You migth wanna check out the ConsoleLibrary
I didn't use it, but from the article/demos it seems it would allow you to do bunch of neat stuff on the console.
假设您在每个循环中再次从左上角写入全屏,您可以简单地将 Clear() 替换为:
并覆盖前一个屏幕。
Assuming you Write a full screen from topleft again in every loop you could simply replace the Clear() with:
And overwrite the previous screen.