【问题标题】:Allegro 5 how to draw a scaled bitmap regionAllegro 5 如何绘制缩放的位图区域
【发布时间】:2016-04-14 02:46:43
【问题描述】:

我的 allegro 5 游戏需要绘制一个 tilesheet 的区域,然后我使用 al_draw_bitmap_region,但现在我添加了更改屏幕分辨率的功能,所以现在我还需要缩放该位图,但 allegro 5 没有像 al_draw_scaled_bitmap_region 一样,它有 al_draw_bitmap_region andal_draw_scaled_bitmap` 但不是两者都有。 有人可以帮助我如何使用两者?

【问题讨论】:

    标签: c++ allegro5


    【解决方案1】:

    没有al_draw_scaled_bitmap_region,但是有 al_draw_tinted_scaled_rotated_bitmap_region。你可以通过'默认' 值到你不需要的参数。

    al_draw_tinted_scaled_rotated_bitmap_region(
       bitmap,
       sx, sy, sw, sh,      // source bitmap region
       al_map_rgb(1, 1, 1), // color, just use white if you don't want a tint
       cx, cy,              // center of rotation/scaling
       float dx, float dy,  // destination
       xscale, yscale,      // scale
       0, 0));              // angle and flags
    

    您还可以使用变换来缩放位图:

    ALLEGRO_TRANSFORM trans, prevTrans;
    
    // back up the current transform
    al_copy_transform(&prevTrans, al_get_current_transform());
    
    // scale using the new transform
    al_identity_transform(&trans);
    al_scale_transform(&trans, xscale, yscale);
    al_use_transform(&trans);
    
    al_draw_bitmap_region(*bitmap, sx, sy, sw, sh, dx, dy, 0));
    
    // restore the old transform
    al_use_transform(&prevTrans);
    

    【讨论】:

    • 您还可以将整个游戏绘制到正常的屏幕外缓冲区,然后在最后缩放该单个图像,然后再将其呈现到屏幕上
    猜你喜欢
    • 2020-12-22
    • 1970-01-01
    • 1970-01-01
    • 2020-09-18
    • 2018-06-13
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多