【问题标题】:How can I use two buffer in one screen ? Is it possible ? (Allegro.h)如何在一个屏幕中使用两个缓冲区?是否可以 ? (快板.h)
【发布时间】:2014-12-23 15:36:51
【问题描述】:

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

重点是

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

这是我的代码:

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);

【问题讨论】:

    标签: c++ c allegro


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2014-01-29
      • 1970-01-01
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多