【问题标题】:Allegro 4.2.1, removing bmp background colorAllegro 4.2.1,去除 bmp 背景色
【发布时间】:2010-02-18 19:49:55
【问题描述】:

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

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

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

【问题讨论】:

    标签: c++ allegro


    【解决方案1】:

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

    • 在拨打set_gfx_mode()之前先拨打set_color_depth(32)

    • 调用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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多