所以 atm 我在这段代码中使用 swapbuffers 来刷新它:
#include "graphics.h"
void drawGridOnX(int xtotal, int ytotal);
int levelcode[400][45][100];
void decodelevelAndDraw();
void main() {
initwindow(1600, 900,"Testscreen",0,0,true,true);
int gridposx = 0, gridposy = 0, diffx = 0, diffy = 0, xtotal=0, ytotal = 0,distanceFromMouse=50;
while (1) {
setbkcolor(9);
ytotal = 0;
diffx = mousex() - gridposx;
while (gridposx < mousex()&&diffx>=70) {
gridposx += 70;
}
while (gridposx > mousex()&&diffx<=-70 + distanceFromMouse) {
gridposx =gridposx-70;
}
diffy = mousey() - gridposy;
while (gridposy < mousey() && diffy >= 70) {
gridposy += 70;
}
while (gridposy > mousey() && diffy <= -70+distanceFromMouse) {
gridposy = gridposy - 70;
}
while (ytotal < 900) {
drawGridOnX(xtotal, ytotal);
ytotal += 70;
}
if (WM_LBUTTONDOWN) {
levelcode[gridposx/70][gridposy/70][0]=1;
printf("CLICK");
}
decodelevelAndDraw();
readimagefile("question.bmp", gridposx,gridposy, 70+gridposx, 70+gridposy);
printf("gridposx:%d\tgridposy:%d\ttitlenumberx:%d\ttitlenumbery%d",gridposx,gridposy,gridposx/70,gridposy/70);
swapbuffers();
cleardevice();
}
}
void drawGridOnX(int xtotal, int ytotal) {
while (xtotal < 1600) {
rectangle(xtotal, ytotal, 70 + xtotal, 70+ytotal);
xtotal += 70;
}
}
void decodelevelAndDraw() {
int x = 0, y = 0;
while (y != 12) {
while (x != 22) {
if (levelcode[x][y][1] == 1) {
readimagefile("question.bmp", x*70, y*70, 70 + x*70, 70 + y*70);
}
x++;
}
y++;
}
}
所以我在绘图过程结束时使用它,然后是一个清晰的设备。在播放动画或在背景中绘制某些东西(被删除)时,这有点工作。我不明白我应该如何使用它。我知道它用于双缓冲,它应该用旧的交换掉预先生成的下一帧,但我在任何地方都看到它的解释很糟糕。我如何有效地使用交换缓冲区,以便我可以在背景中播放动画和绘制东西(就像我的程序在玩家左键单击时应该做的那样)而不会消失?