1

我一直在 allegro 4.2.1 中构建游戏,需要帮助删除特定颜色以使其不可见。背景颜色为 (255, 0, 255)。我去过以下网站,但它们对我帮助不大:

http://www.allegro.cc/forums/thread/599210 , http://www.cpp-home.com/tutorials/258_1.htm

如果有人能给我举个例子,我会很高兴。

4

1 回答 1

1

您需要执行以下操作来启用透明像素:

  • 打电话set_color_depth(32)前打电话set_gfx_mode()

  • 调用后加载图像set_gfx_mode()

  • 使用masked_blit()draw_sprite()绘制图像。

如果您执行上述操作,所有“神奇粉色”像素(100% 红色、0% 绿色、100% 蓝色)都将被视为透明。

BITMAP *bmp;
allegro_init();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
clear_to_color(screen, makecol(0,0,0));

// once the video mode has been set, it is safe to create/load images.
// this bitmap will be 640x480 with pure pink.
bmp = create_bitmap(640, 480);
clear_to_color(bmp, makecol(255,0,255));
rectfill(bmp, 100,100, 200,200, makecol(255,255,255));

draw_sprite(screen, bmp, 0, 0);

// or
// masked_blit(bmp, screen, 0,0, 0,0, 640,480);
于 2010-03-01T08:29:38.853 回答