你如何使用c ++的allegro做背景? [英] how do you make a background in allegro with c++?
本文介绍了你如何使用c ++的allegro做背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是用allegro编程的新程序,我想改变我的程序的背景颜色从比一个更愉快的黑色 haha :)有人可以帮助吗?
仅供参考。
#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();
解决方案
要创建背景位图,请尝试:
/ *在RAM中创建位图* /
BITMAP * bmp = create_bitmap(SCR_X,SCR_Y);
然后尝试将bmp清除为不同的颜色: / p>
/ *将屏幕清除为红色* /
clear_to_color(bmp,makecol 255,0,0));
来自文件:
bmp = load_bitmap(image.pcx,palette);
然后你只需要在你的屏幕上拼接这个位图,像这样:
/ *在屏幕上闪烁bmp。 * /
blit(bmp,screen,0,0,0,0,bmp-> w,bmp-> h);
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();
解决方案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);
这篇关于你如何使用c ++的allegro做背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文