简体   繁体   中英

Double buffering in the console (display)?

I'm trying to create a console pong game but have run into the following issue. I have the following:

int main()
{
    while(1)
    {
        clearScreen();

        std::stringstream sstr;
        for(int i = 0; i < 20; ++i)
        {
            sstr << "Mooooooo \n";
        }
        printf(sstr.str().c_str());
        restThread(50);
    }
    return 0;
}

The output I would expect is for Moo to be written 20 times and for the contents of the screen to never actually change. However it flickers from time to time. I suspect this is because the output is shown to the screen before it is fully drawn. Is there a way around this? eg, not showing the user anything until all the characters have been drawn to the screen?

Thanks

There's the curses/ ncurses library, which requires you to refresh the screen before anything is displayed. It's pretty ubiquitous in terms of platform support.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM