如何在一个屏幕中使用两个缓冲区?可能吗 ? (Allegro.h)

时间:2014-12-23 15:36:52

标签: c++ c allegro

我正在使用Microsoft Visual Studio 2010,尝试使用Allegro.h库编写游戏代码。

重点是

  1. 我正在使用缓冲区用draw_sprite绘制建筑物(screen,buf1,0,0);
  2. 之后,我想在该屏幕中移动位图球图像
  3. 当我移动.bmp图像时,我再次使用buf1(相同的缓冲区),但我应该清理buf1以创建一个动态图像
  4. 当我自然地这样做时,我会错过缓冲区中的所有内容,但我希望在游戏过程中建筑背景。
  5. 如何在一个屏幕中使用两个缓冲区?
  6. 这是我的代码:

    void  BinaCizdir1(BITMAP *buf1){
        int r;
        int renk;
        int say=0;
        BITMAP *turuncu_beton=load_bitmap("turuncu.bmp",NULL);
        BITMAP *sari_beton=load_bitmap("sari.bmp",NULL);
        BITMAP *pembe_beton=load_bitmap("pink.bmp",NULL);
        BITMAP *oyunu1_resmi=load_bitmap("topbu.bmp",NULL);
    
        //Birinci oyuncunun x koordinatını belirledik.Random olarak!
        int oyuncu1_y_koor=0;
    
        int oyuncu1_x_koor1= (1+rand()%4);
        if (oyuncu1_x_koor1==1){
            oyuncu1_x_koor1=30;
        }
        if (oyuncu1_x_koor1==2){
            oyuncu1_x_koor1=150;
        }if (oyuncu1_x_koor1==3){
            oyuncu1_x_koor1=270;
        }if (oyuncu1_x_koor1==4){
            oyuncu1_x_koor1=390;
        }
    
    
        if(kontrol==0){
            renk=(rand()%3);r= (1+rand()%6)*30;
            for(int x=0;x<1080;x=x+30){
                for(int y=600;y>450-r;y=y-30){
                    if(oyuncu1_x_koor1==x){
                        oyuncu1_y_koor=390-r;
                        draw_sprite(buf1,oyunu1_resmi,oyuncu1_x_koor1,oyuncu1_y_koor);
                    }
                    if(renk==0){
                        draw_sprite(buf1,turuncu_beton,x,y);
                    }
                    if(renk==1){
                        draw_sprite(buf1,sari_beton,x,y);
                    }
                    if(renk==2){
                        draw_sprite(buf1,pembe_beton,x,y);
                    }
                }
                if( say%3==2 && x!=1020){
                    renk=(rand()%3);
                    r= (1+rand()%6)*30;
                    x=x+30;
                }
                say++;
                /*
               velocityY = velocityY +acc*dt; // updating the y component of the velocity  
               x = x + (velocityX*dt); // updating the x position  
               y = y + (velocityY*dt) + 0.5*acc*(dt*dt);// updating the y position. 
               rest(5);       
               draw_sprite(buf1,oyunu1_resmi,x,y);
              */
            }
             kontrol=1;
        }
        draw_sprite(screen,buf1,0,0);
    }
    

    这是我移动的bmp图片代码:

      velocityY = velocityY +acc*dt; // updating the y component of the velocity  
      x = x + (velocityX*dt); // updating the x position  
      y = y + (velocityY*dt) + 0.5*acc*(dt*dt);// updating the y position. 
      rest(5);       
      draw_sprite(buf1,oyunu1_resmi,x,y);
    

1 个答案:

答案 0 :(得分:0)

对不起,我不太明白这个说法;这听起来像是在询问双缓冲。

您将把建筑物绘制到屏幕外的帧缓冲区。 然后你将你的球画到屏幕外的帧缓冲区。 然后,您将等待屏幕的垂直刷新。 (这一天这个步骤可能是由Allegro自动完成的) 然后,您将交换缓冲区,以使屏幕外帧缓冲区成为屏幕上的。 (重复)

比照。 https://wiki.allegro.cc/index.php?title=Double_buffering