Update console without flickering - c++

前端 未结 3 1390
庸人自扰
庸人自扰 2020-12-04 13:33

I\'m attempting to make a console side scrolling shooter, I know this isn\'t the ideal medium for it but I set myself a bit of a challenge.

The problem is that whene

3条回答
  •  醉话见心
    2020-12-04 14:26

    system("cls") is the cause of your problem. For updating frame your program has to spawn another process and then load and execute another program. This is quite expensive. cls clears your screen, which means for a small amount of the time (until control returns to your main process) it displays completely nothing. That's where flickering comes from. You should use some library like ncurses which allows you to display the "scene", then move your cursor position to <0,0> without modifying anything on the screen and redisplay your scene "over" the old one. This way you'll avoid flickering, because your scene will always display something, without 'completely blank screen' step.

提交回复
热议问题