我见过一些控制台游戏,屏幕会自行刷新/清除而不会出现烦人的闪烁。我已经尝试了很多解决方案,这是我现在得到的:
while(true)
{
if(screenChanged) //if something needs to be drawn on new position
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
///printf all the time graphics on their right position with SetConsoleCursorPosition
Sleep(33.3f);
}
尽管如此,我还是得到了一些最小的眨眼。有人有想法么?