ADDSPRITE

From Liberty BASIC Family
Jump to navigation Jump to search
Supported in Just BASIC Supported in Liberty BASIC Not supported in Liberty BASIC 5 Not supported in Run BASIC

Description

This command adds a Sprite to a GRAPHICBOX or a Graphics Window, assigning to it a name, and one bitmap name or a list of several bitmaps names.
The bitmap must be loaded first with the LOADBMP command, or created at runtime.
A sprite bitmap must include a mask above and a sprite below, like this:
To delete a Sprite, read REMOVESPRITE.
The Background and Sprites will not show up until a DRAWSPRITES command is issued.

Syntax

GraphicBox Control

  1. Print #Handle.Extension, "addsprite spritename bmpname"
  2. Print #Handle.Extension, "addsprite spritename bmpname1 bmpname2 bmpname3"
  3. #Handle.Extension "addsprite spritename bmpname"
  4. #Handle.Extension "addsprite spritename bmpname1 bmpname2 bmpname 3"

Graphics Type Window

  1. Print #Handle, "addsprite spritename bmpname"
  2. Print #Handle, "addsprite spritename bmpname1 bmpname2 bmpname3"
  3. #Handle "addsprite spritename bmpname"
  4. #Handle "addsprite spritename bmpname1 bmpname2 bmpname3"

Hints

The sprites could be several images of a character walking.
Only one graphic-box or graphics window in a program may use sprites.

Example

This example uses the image from this article. Save it to a folder of your choice and run this code from the same folder.

NOMAINWIN
LOADBMP "BMP","sprite_jb_guy_1.bmp"
Open "Just BASIC - Sprite Demo - Addsprite" For Graphics_nsb_nf as #main
    #main "Trapclose [quit]"
    #main "AddSprite player BMP"
    Timer 56,[redraw]
    Wait

    [redraw]
    #main "Drawsprites"
    Wait

[quit]
Timer 0
Close #main
UNLOADBMP "BMP"
End

Useful Procedures

' Place a useful function using this keyword here