draw_sprite_v_flip(3alleg4)

πŸ’– draw_sprite_v_flip β€” the Allegro manual, but make it cute πŸ’–

okay bestie, we're in the Allegro manual (that's the 3alleg4 section, the game programming library one) and today's main character is a whole little trio of functions that draw your sprite but flipped. yes. mirror mode. slay.


✨ NAME ✨

draw_sprite_v_flip, draw_sprite_h_flip, draw_sprite_vh_flip β€” they draw the sprite transformed onto the destination bitmap. that's the Allegro game programming library, periodt.


🌸 SYNOPSIS 🌸

#include <allegro.h>

void draw_sprite_v_flip(BITMAP *bmp, BITMAP *sprite, int x, int y);

void draw_sprite_h_flip(BITMAP *bmp, BITMAP *sprite, int x, int y);

void draw_sprite_vh_flip(BITMAP *bmp, BITMAP *sprite, int x, int y);

πŸ¦‹ DESCRIPTION πŸ¦‹

so these are literally just like draw_sprite(), except they also flip the image. that's it. that's the whole vibe.

  • draw_sprite_v_flip flips it vertically
  • draw_sprite_h_flip flips it horizontally
  • draw_sprite_vh_flip flips it both ways (overachiever behavior, we love it)

and what does flipping actually mean here? okay so flipping vertically = the y-axis is reversed, and flipping horizontally = the x-axis is reversed, between the source and the destination. it's giving mirror. it's giving reflection.

and here's the tea: this produces exact mirror images, which is NOT the same thing as rotating the sprite. also it is a lot faster than the rotation routine, so if you just want a mirrored sprite, don't be doing the whole rotation thing, okay? it's not that deep. πŸ”₯

heads up bestie: the sprite must be a memory bitmap. no cap. don't come crying to me later.

example time, look at this little animation logic, it ate:

if (key[KEY_RIGHT])
   draw_sprite(screen, hero_right, pos_x, pos_y);
else if (key[KEY_LEFT])
   draw_sprite_h_flip(screen, hero_right, pos_x, pos_y);
else
   draw_sprite(screen, hero_idle, pos_x, pos_y);

see how the hero just flips to face left instead of you needing a whole second bitmap? iconic. efficient. main character energy. πŸ’…


πŸ‘€ SEE ALSO πŸ‘€


okay and finally, the little sign-off at the bottom of the page: this is Allegro, version 4.4.3, and the page is draw_sprite_v_flip(3alleg4). that's the whole footer. mwah. πŸŽ€ go flip something, bestie. 🫢