【问题标题】:how do you make a background in allegro with c++?你如何用c ++在allegro中制作背景?
【发布时间】:2011-07-09 04:23:39
【问题描述】:

我在使用 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();

【问题讨论】:

  • 在 Allegro 4 中,您通常会使用已创建的屏幕外位图缓冲区。最终你会发现你需要清除每一帧并重新绘制帧......所以除了黑色之外没有任何额外的工作。

标签: c++ background allegro


【解决方案1】:

要创建背景位图试试这个:

/* 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这个位图——像这样:

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

【讨论】:

  • clear_bitmap(bmp) 是对clear_to_color(bmp, makecol(0, 0, 0)) 的同义调用。在clear_bmp(...) 之后调用clear_to_color(...) 是一种浪费。只需致电clear_to_color(...)。另外,只需调用BITMAP* bmp = load_bitmap("image.pcx", palette),您无需先“在 RAM 中制作位图”。
【解决方案2】:

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

【讨论】:

  • 是的,我希望我不必画一个矩形
【解决方案3】:
#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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    相关资源
    最近更新 更多