Liberty BASIC Help Online

Sprite Properties
The properties VISIBLE and NAME are discussed in Designating Sprites.  Sprites have several other properties that can be set by the programmer.
Liberty BASIC will automatically cycle through the image list for a sprite, if given the CYCLESPRITE command.  The command also requires the sprite's NAME and a value for the frame count.  A value of "1" will cause the sprite to cycle through all images in its list from first listed to last listed.  A value of "-1" will cause the sprite to cycle through all of its images in the reverse order from which they were listed.  A value equal to one of the images in the list will cause the sprite to cycle to that image.  To cycle forward through all images:
    print #w.g, "cyclesprite smiley 1"
or backwards:
print #w.g, "cyclesprite smiley -1"
For the example with three frogs, Liberty BASIC will cycle through these three images when drawing frames of animation:
Image bm16.GIFImage bm17.GIFImage bm11.GIF
    loadbmp "frog1", "frog1.bmp"
    loadbmp "frog2", "frog2.bmp"
    loadbmp "frog3", "frog3.bmp"
    print #w.g, "addsprite frog frog1 frog2 frog3";
    print #w.g, "cyclesprite frog 1"
Adding ONCE to the CYCLESPRITE command causes the sprite to cycle through its frames of animation, either forward, or backward, only one time, and then stop at the last (or first) frame.  After the single cycle through frames, the sprite will appear as the last (or first) frame until a different cycle command is issued.  This is useful for animations such as explosions.
    print #w.g, "cyclesprite frog 1 once"
A sprite may be scaled to a percentage of its original width and height with the SPRITESCALE command.  A percentage of 200 will cause the sprite to appear twice the original width and height, while a percentage of 50 will cause it to be half as large as the width and height of the loaded bitmap.  To change the size of a sprite to be one and one-half times the width and height of the loaded bitmap:
    print #w.g, "spritescale smiley 150";
Image bm18.GIF
By default, sprites are shown just as they appear in the loaded bitmap.  It is easy to cause them to appear as a mirror image of the loaded bitmap, or flipped, or rotated 180 degrees.  It is not possible to rotate 90 or 270 degrees, so these rotations will require separate sprites/bitmaps.  Sprites can have alterations in both scale and orientation at one time.
    print #w.g, "spriteorient smiley normal";
    print #w.g, "spriteorient smiley flip";
    print #w.g, "spriteorient smiley mirror";
    print #w.g, "spriteorient smiley rotate180";       
  Image bm19.GIF    Image bm20.GIF    Image bm21.GIF    Image bm22.GIF            
A sprite can be moved to the x, y position indicated in the SPRITEXY command.  The following example places the sprite named "smiley" at x=100, y=137:
    print #w.g, "spritexy smiley 100 137";
Liberty BASIC will automatically move a sprite each time a new frame is drawn, if the SPRITEMOVEXY command is issued.  The following command moves the sprite named "smiley" 5 pixels in the x direction and 2 pixels in the y direction each time a new animation frame is drawn.
    print #w.g, "spritemovexy smiley 5 2";
A sprite is stopped from moving automatically by the SPRITEMOVEXY command and values of 0 for the x and y movement:
    print #w.g, "spritemovexy smiley 0 0";
The spritetravelxy command sets up a condition where a sprite moveS to a given location at a certain speed. Each time a drawsprites command is issued, the sprite moves the appropriate amount towards its goal. When it reaches its destination, it will fire an event using the handler specified, and it will stop moving.
    print #w.g, "spritetravelxy smiley 300 200 5 [landed]";
The centersprite command causes any commands that refer to the sprite's location to use the center of the sprite as the x, y location, rather than using the default upper left corner of the sprite as the x, y location.
    print #w.g, "centersprite smiley";
The spriteoffset command causes the displayed location of the sprite to be offset by the values indicated from the actual coded x, y location. If a sprite is given a spritexy command that calls for it to be located at 100, 100, but the spriteoffset command is in force, giving offsets of 20x and 50y, the sprite appears at 120, 150. This alters the display coordinates of the sprite, but not its actual coordinates, which remain 100,100 in this example.
    print #w.g, "spriteoffset smiley 20 50";
Z order means the order in which the sprites are drawn. A sprite on the bottom of the z order is drawn first, so sprites drawn after it will appear to be on top of it. A sprite at the top of the z order is drawn last, so other sprites appear underneath it. To bring a sprite to the top of the z order:
    print #w.g "spritetofront smiley";
To send a sprite to the bottom of the z order:
    print #w.g "spritetoback smiley";
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.  Now, we're ready to start drawing the animated sprites!  See the section on Drawing and Collision Detection!

Copyright (C) 2003 Shoptalk Systems
Liberty BASIC -