riwbspritelib
This library puts hardware sprites on the Workbench screen, or any
other Intuition screen, in a way the system allows: it uses the sprite
functions of graphics.library. A Blitz shape is converted into a
sprite and gets one of the 8 sprite channels; the commands then name
the sprite by its channel, 0 to 7. A new sprite appears when
MoveWBSprite or ChangeWBSprite first places it.
All commands work in Amiga mode only. MoveWBSprite and
ChangeWBSprite need the address of the screen’s ViewPort, which the
function ViewPort of the screens library gives. Sprites the
program does not free are freed when it ends.
The shape is converted with a width rounded down to a multiple of 16, so a shape 20 pixels wide shows its left 16 pixels; a shape narrower than 16 pixels gives no sprite. On Kickstart 3.0 and newer the sprite functions of the system decide which shapes they accept; on the Workbench screen of an A600 and of an A1200 alike, they refuse a sprite 32 pixels wide. On Kickstart 1.x and 2.x a sprite is 16 pixels wide with up to 3 colours: the shape must have 1 or 2 planes and be narrower than 32 pixels, and another shape gives no sprite.
With runtime error checking, the commands refuse a channel outside 0
to 7 (-1 to 7 for GetWBSprite), a shape of height 0 or of depth 0
or more than 8, a shape too big for a sprite below Kickstart 3.0, and
WBSpriteX and WBSpriteY refuse a channel without a sprite.
A sprite made of a loaded shape on any free channel of the Workbench screen, moved to 100,50:
LoadShape 0,"sprite.shape"
WbToScreen 0
vp.l=ViewPort(0)
ch=GetWBSprite(0,0,0,-1)
If ch>=0
MoveWBSprite vp,100,50,ch
MouseWait
FreeWBSprite ch
EndIfLibrary number 10.
Commands
ChangeWBSprite
Gives the sprite of a channel the image of another shape, at the same position. As a function it returns -1 on success and 0 if the channel has no sprite of this library, the shape has no data or does not fit, or the change failed.
Statement or function, result .b. Help text: viewport,sprite_channel,shape#
Arguments: .l, .l, .w
With runtime error checking, a channel outside 0 to 7 and a shape of height or depth 0, of a depth above 8 or too big for a sprite below Kickstart 3.0 are runtime errors.
FreeWBSprite
Frees the sprite of a channel and gives the channel back to the system. Nothing happens if the library has no sprite on that channel.
Statement. Help text: sprite_channel
Arguments: .b
With runtime error checking, a channel outside 0 to 7 is a runtime error.
GetWBSprite
Makes a sprite of a shape and takes the sprite channel spritechannel for it, or any free channel for -1. Returns the channel, 0 to 7, or -1 if it got no sprite.
Function, result .l. Help text: x,y,shape[,spritechannel]
Arguments: .w, .w, .w, .l
x and y are stored as the sprite’s position; MoveWBSprite moves
it and shows the sprite. The channel is not optional, although the
help shows it so.
The result is -1 if graphics.library could not be opened, if the shape has no data or does not fit, if the channel is taken or if there is no memory. With runtime error checking, a channel outside -1 to 7, a shape of height 0 and a shape of depth 0 or more than 8 are runtime errors, and so is a shape too big for a sprite below Kickstart 3.0.
MoveWBSprite
Moves the sprite of a channel to x,y of the ViewPort at viewport. As a function it returns -1 if it moved the sprite and 0 if the library has no sprite on that channel.
Statement or function, result .b. Help text: viewport,x,y,sprite_channel
Arguments: .l, .w, .w, .l
With runtime error checking, a channel outside 0 to 7 is a runtime error.
WBSpriteX
The x position of the sprite of a channel.
Function, result .w. Help text: sprite_channel
Arguments: .w
With runtime error checking, a channel outside 0 to 7 or without a sprite of the library is a runtime error; without it, the result for such a channel means nothing.
WBSpriteY
The y position of the sprite of a channel.
Function, result .w. Help text: sprite_channel
Arguments: .w
With runtime error checking, a channel outside 0 to 7 or without a sprite of the library is a runtime error; without it, the result for such a channel means nothing.