2011-09-07 51 views
0

即時通訊試圖做一個簡單的程序,有一個BITMAP是「背景」,另一個BITMAP,我可以移動,我嘗試了不同的方式,如直接繪製背景屏幕,嘗試製作兩個緩衝區,兩個BITMAPS在一個緩衝區中。現在即時運行程序與兩個在循環中調用兩次緩衝區。但可移動的BITMAP閃爍。Allegro C++;閃爍BITMAP

#include <allegro.h> 


int main(int argc, char *argv[]) 


{ 
allegro_init(); 
install_keyboard(); 
set_color_depth(16); 
set_gfx_mode(GFX_AUTODETECT, 640,480,0,0); 



BITMAP *my_pic = NULL; 
my_pic = load_bitmap("image.bmp", NULL); 
BITMAP *my_pics; 
my_pics = load_bitmap("picture.bmp", NULL); 
BITMAP *buffer = NULL; 
buffer = create_bitmap(640,480); 
BITMAP *bitty=NULL; 
bitty = create_bitmap(640,480); 





int my_pic_x = 0; 
int my_pic_y = 0; 
int my_pics_x=0; 
int my_pics_y=0; 

while(!key[KEY_ESC]) 
{ 


    if(key[KEY_RIGHT]) 
    { 
     my_pic_x ++; 
    } 
    else if(key[KEY_LEFT]) 
    { 
     my_pic_x --; 
    } 
    else if(key[KEY_UP]) 
    { 
     my_pic_y --; 
    } 
    else if(key[KEY_DOWN]) 
    { 
     my_pic_y ++; 
    } 

draw_sprite(bitty,my_pic,my_pic_x,my_pic_y);       
//draw_sprite(screen, my_pic, 0, 0); 
blit(bitty, screen, 0,0,0,0,640,480); 
clear_bitmap(bitty); 

draw_sprite(buffer,my_pics,my_pics_x,my_pics_y); 
blit(buffer, screen, 0,0,0,0,640,480); 
clear_bitmap(buffer); 




} 


destroy_bitmap(my_pic); 
destroy_bitmap(my_pics); 
destroy_bitmap(buffer); 
destroy_bitmap(bitty); 
return 0; 
} 
END_OF_MAIN() 

回答

1

你有這樣的作品代碼:

// draw the my_pic sprite to bitty 
draw_sprite(bitty,my_pic,my_pic_x,my_pic_y); 
// status now: bitty contains my_pic 

// draw bitty to the screen 
blit(bitty, screen, 0,0,0,0,640,480); 
// status now: screen contains my_pic by way of bitty 

// clear bitty 
clear_bitmap(bitty); 
// status now: screen contains my_pic by way of a former 
// version of bitty, bitty is now empty 

// draw my_pics to buffer 
draw_sprite(buffer,my_pics,my_pics_x,my_pics_y); 
// status now: screen contains my_pic, bitty is empty, 
// buffer contains my_pics 

// draw buffer to the screen 
blit(buffer, screen, 0,0,0,0,640,480); 
// status now: screen and buffer both contain my_pics, 
// bitty is empty 

// clear the buffer 
clear_bitmap(buffer); 
// status now: 
// 
// screen contains my_pics 
// bitty and buffer are empty 

我可以想象你想要更多的東西一樣:

// clear buffer 
clear_bitmap(buffer); 
// status now: buffer is empty 

// draw my_pic to buffer 
draw_sprite(buffer,my_pic,my_pic_x,my_pic_y); 
// status now: buffer contains my_pic 

// draw my_pics to buffer 
draw_sprite(buffer,my_pics,my_pics_x,my_pics_y); 
// status now: buffer contains my_pic, with my_pics on top 

// copy buffer to the screen 
blit(buffer, screen, 0,0,0,0,640,480); 
// status now: buffer and screen contain my_pic, with my_pics on top 
+0

天啊!!!!謝謝你,先生!它的工作和它的真棒!感謝所有的評論讓我明白了我的錯誤。 –