MKSPRT: Making sprites

Purpose

You can display sprites with the PWsprite keyword, or by including a sprite in a loose item definition (see the loose item type tags). In both cases you must give the address where you can find the sprite. How can you make an address where one can find a sprite? This is achieved with MKSPRT. This takes several parameters, one of them a string array containing the data setting up the sprite. The keyword takes this data, builds the sprite, and returns the address where the sprite lies.

Syntax

The syntax for this keyword is relatively simple:

address = MKSPRT (sprite$,x_columns%,[,xo%,yo%])

Example


         dim my_sprite$(9,7) 
                   rem 10 lines with 7 pixels each
         a$(0)= '   w   '
         a$(1)= '  waw  '
         a$(2)= ' waraw '
         a$(3)= 'waaraaw'
         a$(4)= ' waraw '
         a$(5)= ' waraw '
         a$(6)= ' waraw '
         a$(7)= ' waraw '
         a$(8)= ' waraw '
         a$(9)= ' wwwww '
         :
         address=MKSPRT (my_sprite$,7,4,0)
         :
         sprite_name$="anything_sp4"
         for lp=1 to len(sprite_name$)
            poke address+lp-1,code(sprite_name$(lp))
         end for lp
         poke address+lp,0
         :


With this example I've built a small sprite in the shape of an upwards pointing arrow. The sprite is black (the 'a's) but surrounded by a white border, and the innermost column is red. The origin is set to the uppermost point of the arrow i.e. pixel (4,0). Finally, the name of the sprite is poked into the FileInfo area (using POKE$ for this would be better!).
PROGS, Professional & Graphical Software
last edited 1996 Dec 26 (wl)