draw_sprite_v_flip(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

πŸ’– draw_sprite_v_flip(3) β€” the Allegro manual, but make it make sense πŸ’–

okay bestie, so this is a page from the Allegro manual β€” the Allegro game programming library ✨ β€” and today we're talking about three little functions that flip your sprites around like they're doing a mirror selfie πŸ“ΈπŸ’…


✨ NAME ✨

draw_sprite_v_flip, draw_sprite_h_flip, draw_sprite_vh_flip β€” these bad boys draw your sprite over to the destination bitmap, but transformed first. iconic behaviour, no cap πŸ¦‹


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

three functions, same exact signature, different flip energy. we love a consistent queen πŸ‘‘


πŸŽ€ DESCRIPTION πŸŽ€

so like… these are draw_sprite() but with a plot twist πŸ’€ they do the normal drawing thing, but additionally flip the image vertically, horizontally, or both, depending on which one you call.

let's break down the flip lore, because the way these actually work matters:

  • flipping vertically means the y-axis is reversed between the source and the destination πŸ™ƒ
  • flipping horizontally means the x-axis is reversed between the source and the destination πŸ”„

and the result? exact mirror images ✨ and ngl, that is not the same thing as rotating the sprite. like, at all. but here's the slay: it is a lot faster than the rotation routine ⚑ so if all you need is a mirror, don't be out here doing extra work.

🫢 oh and also β€” the sprite must be a memory bitmap. not optional. remember that bestie.

here's the example from the page, verbatim, because it's lowkey a perfect little vibe check on how you'd actually use this:

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 she's facing right with a normal draw_sprite(), then facing left with draw_sprite_h_flip() using the same hero_right bitmap? that's the whole point bestie. one sprite, two directions, zero extra art assets. main character energy fr fr πŸ‘‘πŸ’–


πŸ’œ SEE ALSO πŸ’œ

go read those too, iykyk πŸ“šβœ¨


and that's the tea, bestie πŸ“ this was Allegro, version 4.4.3, serving you this very page as draw_sprite_v_flip(3) β€” periodt πŸ’…πŸ’–πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from