如何有效地清除屏幕

时间:2023-02-12 19:18:07

Whenever I try to make a game or something that requires the rapid clearing of a screen, I've used system("CLS"). I now know that that is not good to use so I tried using a for loop to print new lines rapidly. While this works it looks really weird and less clear. I've seen people try to use STRING to clear a screen but whenever I try it it never works. How can I clear my screen efficiently and cleanly.

每当我尝试制作游戏或需要快速清除屏幕的东西时,我都使用了系统(“CLS”)。我现在知道这不好用,所以我尝试使用for循环快速打印新行。虽然这种方法很有效但看起来很不清楚。我见过人们尝试使用STRING来清除屏幕,但每当我尝试它时它都无法正常工作。如何高效,干净地清除屏幕。

1 个解决方案

#1


0  

There's no standard way to clear the screen. But in any case, actually clearing the terminal and redrawing will be far too slow and glitchy for many games.

清除屏幕没有标准方法。但无论如何,实际上清理终端并重新绘制对于许多游戏来说都会太慢而且不稳定。

You should use either your OS's native terminal handling functions, or a cross-platform library that abstracts them.
I'd recommend ncurses, which is the latter. It basically provides an interface akin to a double-buffered graphics API, and handles all of the actual terminal twiddling so the frame swap is as fast as possible.

您应该使用操作系统的本机终端处理功能,或者使用抽象它们的跨平台库。我推荐ncurses,后者是后者。它基本上提供了一个类似于双缓冲图形API的接口,并处理所有实际的终端twiddling,因此帧交换尽可能快。

#1


0  

There's no standard way to clear the screen. But in any case, actually clearing the terminal and redrawing will be far too slow and glitchy for many games.

清除屏幕没有标准方法。但无论如何,实际上清理终端并重新绘制对于许多游戏来说都会太慢而且不稳定。

You should use either your OS's native terminal handling functions, or a cross-platform library that abstracts them.
I'd recommend ncurses, which is the latter. It basically provides an interface akin to a double-buffered graphics API, and handles all of the actual terminal twiddling so the frame swap is as fast as possible.

您应该使用操作系统的本机终端处理功能,或者使用抽象它们的跨平台库。我推荐ncurses,后者是后者。它基本上提供了一个类似于双缓冲图形API的接口,并处理所有实际的终端twiddling,因此帧交换尽可能快。