【问题标题】:Allegro c++; flashing BITMAP快板 C++;闪烁的位图
【发布时间】:2011-09-07 02:50:25
【问题描述】:

我正在尝试制作一个简单的程序,其中一个 BITMAP 是“背景”,另一个 BITMAP 可以移动,我尝试了不同的方式,例如将背景直接绘制到屏幕上,尝试制作两个缓冲区,我尝试将两者都放在位图在一个缓冲区中。现在我在循环中调用两次的缓冲区中运行程序。但可移动的 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() 

【问题讨论】:

    标签: c++ bitmap buffer allegro


    【解决方案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
    

    【讨论】:

    • 天哪!!!!谢谢你,先生!它奏效了,太棒了!感谢所有让我理解我的错误的评论。
    猜你喜欢
    • 2023-04-02
    • 2011-02-06
    • 1970-01-01
    • 2014-03-19
    • 2013-05-27
    • 1970-01-01
    • 2012-01-12
    • 2017-09-08
    • 1970-01-01
    相关资源
    最近更新 更多