how do you make a background in allegro with c++?

好久不见. 提交于 2019-12-11 09:58:09

问题


i'm fairly new at programming with allegro, and i wanna change the background color of my programs from something more pleasant than black haha :) can some one help please?

and just for a reference of what im doing

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

回答1:


To create backgroud bitmap try this:

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

then try this to clear bmp to some different color:

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

or this to load bitmap from file:

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

Then you just need to blit this bitmap with your screen - like this:

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



回答2:


Draw a screen-sized rectangle that is the color you want the background to be. Or just use clear_bitmap to clear the screen.




回答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;
}


来源:https://stackoverflow.com/questions/6632697/how-do-you-make-a-background-in-allegro-with-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!