|Liberty BASIC Help Online
A sprite bitmap must include a mask above and a sprite below, like this:
The bitmap must be loaded with the LOADBMP command:
loadbmp "smiley", "smiley.bmp"
The command to add the sprite to the program is ADDSPRITE. It designates the NAME to give this sprite, and then the name for the sprite bitmap that was given with LOADBMP. These names can be the same, as in this example:
print #w.g, "addsprite smiley smiley";
Or, the designated sprite NAME can be different from the LOADBMP name. Below, the bitmap is named "smiley" when it is loaded, and it is given the spritename, "guy".
loadbmp "smiley", "smiley.bmp"
print #w.g, "addsprite guy smiley";
The spritename is used to refer to this sprite when setting its properties, or issuing commands to it. The image for a designated sprite can be changed by issuing the ADDSPRITE command again:
loadbmp "frown", "frown.bmp"
print #w.g, "addsprite guy frown";
None of the properties of the "guy" sprite change when the image is changed.
All added sprites will be drawn in each frame of animation. The SPRITEVISIBLE command is used to specify whether a sprite is visible or not.
A sprite is hidden by issuing SPRITEVISIBLE, the sprite name, and "off".
print #w.g, "spritevisible guy off";
A sprite is shown by issuing SPRITEVISIBLE, the sprite name, and "on".
print #w.g, "spritevisible guy on";
INVISIBLE SPRITES AND COLLISIONS
MULTIPLE VERSIONS OF A SPRITE
It is possible to have several different versions of a sprite image. When the image moves, it cycles through these versions to create the illusion of real movement. The versions might look like this:
The individual bitmaps for the sprite images must be loaded with LOADBMP. The bitmaps for the frog look like this:
The code to load them looks like this:
loadbmp "frog1", "frog1.bmp"
loadbmp "frog2", "frog2.bmp"
loadbmp "frog3", "frog3.bmp"
print #w.g, "addsprite frog frog1 frog2 frog3";
Now the sprite with the NAME of "frog" contains three individual frog images. To see how to make Liberty BASIC cycle through these images when drawing the frog sprite, see the section on Sprite Properties. Bitmaps can be used multiple times within one sprite designation. Note that "frog2" is used twice here:
print #w.g, "addsprite frog frog1 frog2 frog3 frog2";
ACCESSING INDIVIDUAL IMAGES FROM SPRITE LIST
In the example above, the "frog" sprite consists of three separate frog images. By default, the first image is shown when the sprite is drawn. To show any image from the list, the SPRITEIMAGE command is issued, specifying the image name to be used. In the following example, when the sprite is drawn after this command, it will be drawn as the "frog2" image. In this manner, the image can be changed at any time.
print #w.g, "spriteimage frog frog2";
The individual images of a sprite can be cycled automatically by issuing a CYCLE command, which is discussed along with other sprite properties in Sprite Properties.
To avoid flickering, sprite animation is done invisibly, in memory. A frame of animation is built entirely off-screen. A frame of animation is displayed on the screen only when the command DRAWSPRITES is called. For each frame of animation, perform all functions to set the background image, and to set or change a sprite's properties, then call the DRAWSPRITES command. Learn about updating the display in Drawing adn Collision Detection.
Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/