get_compiled_sprite(3)

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

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

okay bestie, welcome to get_compiled_sprite(3), straight outta the Allegro manual, section 3, game programming library vibes. this one's a banger, fr fr πŸŽ€


✨ NAME ✨

get_compiled_sprite β€” creates a compiled sprite using a bitmap as source. and yes, it's part of the Allegro game programming library. πŸ’…


✨ SYNOPSIS ✨

#include <allegro.h>

COMPILED_SPRITE *get_compiled_sprite(BITMAP *bitmap, int planar);

look at that signature. gorgeous. iconic. no notes. 🫢


✨ DESCRIPTION ✨

so what this does is: it creates a compiled sprite based on the bitmap you hand it. and heads up β€” that bitmap must be a memory bitmap, no cap, that's the rule. πŸ¦‹

now here's the tea: compiled sprites are device-dependent, which means you literally have to tell it whether you want it compiled into a linear or a planar format. it can't read your mind, bestie, you gotta communicate.

so for the second parameter:

  • pass FALSE if you're gonna be drawing it onto memory bitmaps or mode 13h and SVGA screen bitmaps
  • pass TRUE if you're gonna draw it onto mode-X or Xtended mode screen bitmaps

vibe check your target device first, okay? πŸ’€

example time, let's go:

COMPILED_SPRITE *cspr;
BITMAP *bmp;
...
/* Create compiled sprite from an existent bitmap. */
cspr = get_compiled_sprite(bmp, 0);
if (!cspr)
   abort_on_error("Couldn't create compiled sprite!");

/* We don't need the bitmap any more.*/
destroy_bitmap(bmp);

/* Use the compiled sprite. */
...
/* Destroy it when we don't need it any more. */
destroy_compiled_sprite(cspr);

see how she ate that? created it, freed the bitmap, used it, destroyed it. the full circle of life. 🧚

it returns a pointer to the created compiled sprite, or NULL if the compiled sprite could not be created β€” so like, check that return value, don't be out here raw-dogging pointers 😭

⚠️ and remember to free this compiled sprite later to avoid memory leaks! seriously. destroy_compiled_sprite exists for a reason. don't leave her hanging. memory leaks are NOT main character energy. πŸ‘‘

✨ SEE ALSO ✨

go read those too, they're the supporting cast and they deserve their moment. 🌸


and that's the page!! Allegro, version 4.4.3, dated get_compiled_sprite(3) β€” mwah, sending you love, go compile some sprites bestie πŸ’œπŸŒˆβ­

πŸ“¦ where this page comes from