textprintf_centre_ex(3alleg4)

πŸ’– textprintf_centre_ex πŸ’–

okay bestie, so this is textprintf_centre_ex β€” it's a function from Allegro, the game programming library, and it does formatted, centered text output. yes she's that girl. πŸ’…


✨ SYNOPSIS ✨

#include <allegro.h>

void textprintf_centre_ex(BITMAP *bmp, const FONT *f, int x, int y, int
color, int bg, const char *fmt, ...);

like. copy that signature exactly, don't be freestyling it, the compiler WILL humble you. 😭


🌸 DESCRIPTION 🌸

so basically she's textprintf_ex()'s sister, right? same energy, one iconic difference: the x coordinate is the centre of the string, not the left edge. the way that… no more doing mental math to figure out where your text starts. she just centers it for you. slay. πŸ‘‘

heads up though bestie β€” this function shares the text length limitation of textprintf_ex(). so if you were planning to print a whole novel in one call, the vibe check says no. keep it reasonable. 🫢

here's the example, verbatim, no cap:

textprintf_centre_ex(screen, font, SCREEN_W / 2, 120,
                     makecol(0, 100, 243), -1,
                     "Your best score so far was %d!",
                     total_max_points);

look at her. SCREEN_W / 2 for that perfect dead-center x, 120 for the y, a whole makecol(0, 100, 243) for the color, -1 for the bg (transparent vibes, we love her), and then the format string doing its lil %d thing with total_max_points riding along as the argument. main character formatting fr fr. ✨


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page, gorgeous. go center some text, you're literally built for this. πŸ’œ

mwah πŸ’‹ β€” this has been textprintf_centre_ex from the Allegro manual, version 4.4.3, filed under section 3alleg4. thanks for reading bestie, now go make something pretty. πŸŽ€πŸŒˆβ­