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%])
- address
is the address where the sprite lies. ATTENTION, this address is
in a form used for displaying the sprite via the PROforma sprite picture
driver. In other words, the actual sprite data lies at address+60, since it
is preceded by what PROforma calls the FileInfo area. The FileInfo area can
be left empty, ecept for the name of the sprite which must be poked in at
the beginning. The name must end in "_sp4". You should thus use
address+60
if the sprite is intended to be used as a pointer
sprite (in the window/canvas) and address
for anything else.
- sprite$ is the array containing the data for the sprite. This is quite
simple: it must be a two dimensional array. Each line is one line of pixels
for the sprite. Each pixel can be either White, Red, Green, blAck or
transparent - other colours are not allowed (yet) since ProWesS only works
in mode 4. For compatiblity reasons with QPTR, W denotes a white pixel, R a
red one, G a green pixel, A a black one, and ' ' (a space) a transparent
pixel. Transparent pixels show what is underneath. Thus you build up a
sprite line by line, determining the pixels for each line. Don't forget
that the first element in the first dimension of a string array is
element(0).
- x_columns%, an integer, contains the number of pixels per line. This
should normally be equal to the second dimension of the array.
- xo% and yo% are the x and y origins for the sprite. These are not
important if the sprite is not used as a pointer sprite. If the sprite is
used as a pointer sprite, then the origins are used to determine where the
sprite is located (i.e. it is the pixels that corresponds to the origin
that determines in what window the sprite is located).
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)