Liberty BASIC Help Online

How Do Sprites Work?
As was explained in the previous section, bitmaps are rectangular.  Realistic graphics require a way to place the image from a bitmap onto a background without including the image's own background.  If this were to be done with an actual picture on a piece of paper, desired parts of the image could be cut out, and the remaining parts of the picture could be discarded.  This cutout could then be pasted onto the background.  This can be done with bitmaps.
Images are added to a background in layers.  There are two versions of the image, which are called a mask and a sprite.  The mask is put on first.  A mask has a white background.  The shape of the image is the actual mask, and it is all black.  A mask is a black and white image.  Here is a mask for the frog image:
Image bm10.GIF
The sprite is the image as it will appear, with a completely black background:
Image bm7.GIF
Here is the bitmap for the frog sprite.  The mask is directly above the sprite, and together these will be used to draw sprites in Liberty BASIC.  This is a single bitmap:
Image bm11.GIF
It is possible to add a mask to the sprite image using Paint, PaintBrush, or any other painting utility, but the easiest way to add the mask is to use the Liberty BASIC program provided as part of this help file.  Add a mask here.
Sprites are displayed by combining the pixels of the background with the pixels of the mask and sprite bitmaps, using bitwise operations.  The programmer does not need to deal with these operations, because they are done by Liberty BASIC.  A Liberty BASIC sprite bitmap contains the mask above the sprite.  The mask is placed on the background bitmap in memory.  It is not displayed on the screen in this form:
Image bm12.GIF
The mask is now in place.  The next layer adds the sprite, and results in this picture, which is displayed on the screen when a DRAWSPRITES command is issued:
Image bm9.GIF
To avoid flickering, sprite animation is done invisibly, in memory.  When an entire frame of animation is built, it is then transferred to the screen.  IT WILL COVER ANY PREVIOUS GRAPHICS IN THE GRAPHICBOX OR ON THE GRAPHICWINDOW.  See the section on Drawing and Collision Detection for information about adding graphics to a window with Liberty BASIC graphic commands during sprite animation.

Copyright (C) 2003 Shoptalk Systems
Liberty BASIC -