Roberto Jaimes
Roberto Jaimes

Reputation: 105

Allegro 5 how to draw a scaled bitmap region

My allegro 5 game needs to draw a region of a tilesheet then i used al_draw_bitmap_region, but now i added the function to change the screen resolution, so now i also need to scale that bitmap but allegro 5 do not have something like al_draw_scaled_bitmap_region, it have al_draw_bitmap_region andal_draw_scaled_bitmap` but not both. somebody can help me how use both?

Upvotes: 0

Views: 2128

Answers (1)

rcorre
rcorre

Reputation: 7218

There is no al_draw_scaled_bitmap_region, but there is al_draw_tinted_scaled_rotated_bitmap_region. You can just pass 'default' values to the parameters you don't need.

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

You could also use transforms to scale your bitmap:

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

Upvotes: 1

Related Questions