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);
}
Run Code Online (Sandbox Code Playgroud)
我正在写一个游戏,我有一个由 10 个角色组成的人物。我希望当单击某些箭头按钮时它会在字符数组中移动。问题是这个游戏根本不流畅。使用时Console.Clear()
,控制台会反复闪烁,这很烦人。这个问题有什么解决办法吗?(如果我不想使用Console.SetCursorPosition()
,因为它会让制作这个游戏变得更加困难)。
尝试将所有场景汇总到 1 个字符串中,而不是一次绘制它,这会将闪烁效果(隐藏)到某个点:
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);
Run Code Online (Sandbox Code Playgroud)