你如何用c ++制作allegro的背景?

时间:2011-07-09 04:23:40

标签: c++ background allegro

我在使用allegro进行编程方面相当新,我想改变我的程序的背景颜色,使其比黑色更令人愉快哈哈 :)可以帮助一些人吗?

仅供参考我正在做什么

#include <allegro.h>

BITMAP* buffer;
BITMAP* bmp;
int cursor_x = 20;
int cursor_y = 20;

int getMouseInfo(){
     if(mouse_b & 1){
                  cursor_x = mouse_x;
                  cursor_y = mouse_y;
      return 1;
     }
  return 0;
}
void updateScreen(){

     show_mouse(NULL);
     circlefill ( buffer, cursor_x, cursor_y, 60, makecol( 0, 255 , 0));
     draw_sprite( screen, buffer, 0, 0);  
}
int main(){

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

    buffer = create_bitmap( 640, 480);     


    show_mouse(screen);        

    while( !key[KEY_ESC])
 {
  int switcher=1;
  while(getMouseInfo()) 
  { 
   updateScreen();
   if(getMouseInfo()==0) switcher=0;
  }
  if(switcher==0) show_mouse(screen);

    }

 return 0; 
}
END_OF_MAIN();

3 个答案:

答案 0 :(得分:2)

要创建背景位图,请尝试以下方法:

/* Make a bitmap in RAM. */
  BITMAP *bmp = create_bitmap(SCR_X, SCR_Y);

然后尝试将bmp清除为某种不同的颜色:

  /* Clear the screen to red. */
  clear_to_color(bmp, makecol(255, 0, 0));

或者这个从文件中加载位图:

bmp = load_bitmap("image.pcx", palette);

然后你只需要在屏幕上显示这个位图 - 就像这样:

  /* Blit bmp on the screen. */
  blit(bmp, screen, 0, 0, 0, 0, bmp->w, bmp->h);

答案 1 :(得分:0)

绘制一个屏幕大小的矩形,它是您想要背景的颜色。或者只需使用clear_bitmap清除屏幕。

答案 2 :(得分:-2)

#include <iostream>
using namespace std;

int main()
{
    cout<<" In the world were gamers play MINECRAFT, where they creating everithing they   can emagine ...\n";
    cin.get();

    return 0;
}