c - 为什么我的窗口每次移动时都不会覆盖它自己?
问题描述
所以我试图在城市防御游戏中拥有一个“阻挡者”
void *defense( void *maxBuildingHeight ){
// the height to put the defense; 2 above the highest building
int *defense_row = ((int *)maxBuildingHeight);
int MAXX, MAXY;
getmaxyx(stdscr,MAXY,MAXX); // screen rows and cols
WINDOW *inputwin = newwin(1,5,(MAXY - (*defense_row + 2)),MAXX/2); //create the window for the defense
char blocker[] = "#####";
wprintw(inputwin, blocker); //the defense
wrefresh(inputwin);
keypad(inputwin, true); // collect the user input
int newX = MAXX/2-2; // the left most position of the defense
BlockerYSpot = (MAXY - (*defense_row + 2));
while ( 1 ){
int input = wgetch(inputwin);
if (input == KEY_LEFT && (newX - 1) >= 0){
newX--;
pthread_mutex_lock(&mutex);
mvwin(inputwin, BlockerYSpot, newX);
wrefresh(inputwin);
pthread_mutex_unlock(&mutex);
}
else if (input == KEY_RIGHT && (newX + 5) < MAXX){ // its +5 due to the length of the blocker
newX++;
pthread_mutex_lock(&mutex);
mvwin(inputwin, BlockerYSpot, newX);
wrefresh(inputwin);
pthread_mutex_unlock(&mutex);
} else if (input == 'q'){
delwin(inputwin);
endwin();
exit( EXIT_FAILURE );
}
CurrentBlockerXSpot = newX;
}//while
}
解决方案
您正在明确刷新inputwin
,而不是下面的窗口。在没有看到您的其余代码的情况下,我假设它是stdscr
. refresh()
(或wrefresh()
)“防御”下方的窗口以重新绘制inputwin
曾经存在的区域。
推荐阅读
- python - Python Netgraph 交互式标签
- azure-logic-apps - 逻辑应用程序-如何从动态属性名称中检索 json 数据
- javascript - 使用 Rollup 编译 Sass 文件
- java - Docker Kafka Avro 控制台消费者 - 连接被拒绝
- mips - 我想改变 bneExample.s 以便它输出三个寄存器值中的最大值
- python - Python:用数字、字母和-_分割字符串
- python - 用python与stockfish交流
- php - 在 WooCommerce 产品评论专业版中编辑评论评论字段
- java - 工作工作目录:检索当前目录时出错:getcwd:无法访问父目录:没有这样的文件或目录
- r - 按 ID,确定最高值,然后将其分配给所有共享 ID