exsprite(3alleg4)

✨ exsprite ✨

okay so bestie, welcome to exsprite from the Allegro manual (that's the Allegro game programming library, section 3alleg4 β€” you're in the right place, promise 🫢). This one's all about datafiles access and sprite animation, and it is so much fun, no cap.


🌸 SYNOPSIS 🌸

#include <allegro.h>

Example exsprite

πŸ’– DESCRIPTION πŸ’–

This example is here to show you how to use datafiles, a whole bunch of different sprite drawing routines, and flicker-free animation. Like, the whole glow-up. ✨

πŸ¦‹ ok but why is animate() written like that?? πŸ¦‹

Bestie, I know you're looking at the animate() routine like πŸ‘€. Let me explain, because as you probably know, VIDEO RAM is much slower than "normal" RAM, so it's advisable to reduce VRAM blits to a minimum. Drawing a sprite on the screen (meaning in VRAM) and then clearing a background for it is not very fast. This example uses a different method which is much faster, but requires a bit more memory.

So here's the tea, step by step:

  1. First, the buffer gets cleared β€” and it's a normal BITMAP, not VRAM, okay? πŸ’…
  2. Then the sprite gets drawn onto it.
  3. When the drawing is finished, that buffer is copied directly to the screen.

So the end result? There's a single VRAM blit instead of blitting/clearing the background and drawing a sprite on it. It's a good method even when you have to restore the background. And of course, it completely removes any flickering effect. Iconic behaviour honestly. πŸ”₯

🌈 the big-background situation 🌈

When one uses a big background (ie. 800x600) and draws something on it, it's wise to use a copy of the background somewhere in memory and restore the background using this "virtual background". When blitting from VRAM in SVGA modes, it's probably the case that drawing routines have to switch banks on the video card. And I think I don't have to remind you how slow that is. 😭

Note that on modern systems, the above isn't true anymore, and you usually get the best performance by caching all your animations in video ram and doing only VRAM->VRAM blits, so there is no more RAM->VRAM transfer at all anymore. And usually, such transfers can run in parallel on the graphics card's processor as well, costing virtually no main cpu time at all. See the exaccel example for an example of this.

πŸ‘‘ SEE ALSO πŸ‘‘

Go read these too, they're all part of the lore, iykyk πŸ’œ:


and that's the whole page, bestie!! πŸŽ€ This one's from Allegro, version 4.4.3, and it's filed under exsprite(3alleg4). go forth and animate, you absolute main character πŸ‘‘πŸ’…βœ¨