【发布时间】:2015-12-14 15:46:07
【问题描述】:
我有闪屏的问题,我知道我需要使用双缓冲来修复它,但我不知道如何以及在我的游戏中添加它的位置。如果由于某种原因我不能使用它,有没有其他方法可以减少闪烁,因为使用更大的地图会变得更糟。以下是部分代码:
`const char HEIGHT=11, WIDTH=54;
unsigned char maze[HEIGHT][WIDTH]={
"##############################",
"# !# # ### ## #",
"# ### ### # !! ### ####### # GAME OF THRANS",
"# # ##### ## # !! # #",
"######## # ## # #### # # R-restart Q-quit",
"# ! # # # # # # # M-menu",
"### ## # ### # #! #### ######",
"# !# # ## # #### # # !! # W",
"# #### ## ## # # # #### # Controls: A-S-D",
"# ## # # #",
"##############################",
};
enemy1.x=14;
enemy1.y=7;
enemy2.x=22;
enemy2.y=9;
enemy3.x=10;
enemy3.y=3;
srand(time (NULL));
while(on){
maze[ppy][ppx]=playerSprite;
maze[gpy][gpx]=goal;
maze[enemy1.y][enemy1.x]=enemy1.sprite;
maze[enemy2.y][enemy2.x]=enemy2.sprite;
maze[enemy3.y][enemy3.x]=enemy3.sprite;
for(int y=0; y<HEIGHT;y++){
cout<<endl;
for(int x=0;x<WIDTH;x++){
cout<<maze[y][x];
}
}
for(;;){
randNum=rand()%randNumMax+1;
cout<<endl;
movement=getch();
switch (movement){
case'w':
if (maze[ppy-1][ppx]!='#' &&(maze[ppy-1][ppx]==' '||(maze[ppy-1][ppx]=='G','N','M','Y','!'))){
maze[ppy][ppx]=' ';
ppy--;
moves++;
if (maze[ppy][ppx]=='!'){
Beep(400,150);
points++;
}`
【问题讨论】:
-
用
cout输出许多字符会给你闪烁的屏幕/whateveryouwannacallit。如果你想使用“控制台图形”,你应该使用curses(特别是:ncursesfor Linux andpdcursesfor Windows)
标签: c++ double-buffering