本文介绍了Console.Clear()闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

while (true)
{
   Console.Clear();
   for (int row = 0; row < 50; row++)
   {
      for (int col = 0; col < 50; col++)
      {
        Console.Write(world[row, col]);
      }
      Console.WriteLine();
   }
      Thread.Sleep(500);
}

我正在写一个游戏,我有一个数字,由10个字符组成。当某些箭头按钮被单击时,我希望它以字符数组的形式移动。问题在于该游戏根本不够流畅。当使用 Console.Clear()时,控制台反复闪烁,这很烦人。有什么解决办法吗? (如果我不想使用 Console.SetCursorPosition(),因为制作这款游戏​​会更加困难)。

I am writing a game and I have a figure, consisted of 10 characters. I want it to move in an array of characters when some of the arrow buttons is clicked. The problem is this game isn't fluid at all. When Console.Clear() is used , the console blinks repeatedly and this is annoying. Is there any solution to this problem? (If I don't want to use Console.SetCursorPosition(), because it makes it much harder to make this game).

推荐答案

尝试将所有场景汇总为1个字符串,而不是一次绘制,这将(隐藏)闪烁的效果特定点:

Try to sum all your scene in 1 string than draw it at once, this will (hide) the blinking effect to a certain point:

string scene = "";

// iterate your array to construct the scene string
for (int row = 0; row < 50; row++)
{
   for (int col = 0; col < 50; col++)
   {
      scene += world[row, col];
   }
   scene += '\n'; // new line
}
Console.Clear();  // thanx David
Console.Write(scene);

这篇关于Console.Clear()闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 08:59