Compiled sprites are stored as actual machine code instructions that draw a specific image onto a bitmap, using mov instructions with immediate data values. This is the fastest way to draw a masked image: on slow machines, up to and including a 486, drawing compiled sprites can be about to five times as fast as using draw_sprite() with a regular bitmap. On newer machines the difference is usually negligible.
Compiled sprites are big, so if memory is tight you should use RLE sprites instead, and what you can do with them is even more restricted than with RLE sprites, because they don't support clipping. If you try to draw one off the edge of a bitmap, you will corrupt memory and probably crash the system. You can convert bitmaps into compiled sprites at runtime, or you can create compiled sprite structures in grabber datafiles by making a new object of type 'Compiled sprite' or 'Compiled x-sprite'.
Returns a pointer to the created compiled sprite, or NULL if the compiled sprite could not be created. Remember to free this compiled sprite later to avoid memory leaks.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 also: draw_compiled_sprite, destroy_compiled_sprite.
See also: get_compiled_sprite.
Hint: if not being able to clip compiled sprites is a problem, a neat trick is to set up a work surface (memory bitmap, mode-X virtual screen, or whatever) a bit bigger than you really need, and use the middle of it as your screen. That way you can draw slightly off the edge without any trouble...
See also: get_compiled_sprite, draw_sprite, draw_rle_sprite, bitmap_mask_color.