Alyce
Jan 27, 2006
- "Removed reference to mask being mirror image, which implies flipping. Changed XOR to raster operations. Changed incorrect instructions about having black in sprite images."
What Are Sprites:
Wikipedia suggests that a Sprite is a class of preternatural legendary creatures commonly associated with elves, fairies, pixies, and spirits. Of course this is not what is meant when Programmers are discussing them in most cases.
Within the realm of Liberty Basic programming we are referring to a two-dimensional pre-rendered graphics figure, usually containing some transparency. Liberty Basic implements sprites using Windows GDI function calls that allow manipulation of graphics with masked areas using
Create a Sprite:
Sprites are created by selecting a suitable graphic (in bitmap form) and applying a mask.- Select an image such as the fairy pictured above.
- Apply a black background to all parts of the image that must be invisible in the finished image. True black must be used, and
replace the blackthat is RGB(0,0,0). The image then looks like this with avery very dark gray.Using the image ofblack background:
- Create a mask. Make a copy of the image. Change all background pixels from black to white. Any part of the image that is to be invisible in the sprite
(or pixymust be pure white, which is RGB (255,255,255). Every other pixel must be black, which is RGB (0,0,0). That is, each part of the image that is to be transparent must be white in the mask, while each part that is to be visible must be black. The mask for the fairy looks like this:
- Create an image that is the same width as
we will call her from nowthe fairy image, but twice the height. Paste the mask part of the sprite onto the top of this double-height image, and paste the fairy part of the sprite onto avoid confusion) we must do the followingthe bottom. Save this mask-over-sprite image to disk in bitmap format. The finished sprite looks like this:
Another way to create a sprite
Want to know more?
Read the entire Liberty BASIC Helpfile section on Sprites. It explains what sprites are, how they work, and how to use them. There are plenty of pictures.Next, check out the articles in the Liberty BASIC Newsletter that pertain to sprites. Download the archives to get all of the images needed to run the demonstration programs.
http://groups.yahoo.com/group/lbnews/
http://babek.info/libertybasicfiles/lbnews/
Beginning Game Programming by Richard Ryles
This series can be found in the following issues:
- 109
- 110
- 111
- 118
Sprite Bytes by Alyce Watson
This series can be found in the following issues:
- 119
- 120
- 121
- 122
- 124
- 125
- 126
- 128
- 129
- 132
- 133
- 134
- 137
You can use Game Workshop to create a skeleton for your game. The standalone version is available here:
It is also part of Liberty BASIC Workshop, available here:
Add your favorite sprite resources!