title: "vbmDrawSpriteSlice" description: TRSE built-in method (from IDE help)
vbmDrawSpriteSlice
Systems: VIC20
Parameters: a, b, b
vbmDrawSpriteSlice( [address1], [byte-start], [byte-end] );
- [address1] - pre-shifted address table
- [byte-start] - the row in the sprite to start drawing from, usually 0
- [byte-end] - the row in the sprite to end drawing, usually the height of the sprite
Description
A flexible sprite routine to display a single 'slice' of a sprite on the bitmap.
The first parameter is an address table pointing to where each pre-shifted frame can be found in memory.
For example: $a000, $a080, $a1000, $a180
The address table will need to be defined if you import your sprites already pre-shifted. If you use the vbmSpriteShiftL / R commands, these will build the address table for you.
There are three ways to draw a sprite:
- vbmDrawSpriteSlice - draws a sprite slice, merging it with the bitmap
- vbmDrawSpriteSliceE - draws a sprite slice, merging it with the bitmap using the EOR operation
- vbmClearSpriteSlice - clears a sprite slice from the bitmap, effectively 'cutting it out'
Example
spr: incbin("spr24x40.bin", $4000); // this sprite is 24 x 40
@define spra0 $4000
@define spra1 $4028
@define spra2 $4050
...
x,y :byte;
// our sprite is 24 x 40. So need 4 byte columns for pre-shifted data
// will pre-shift in increments of 2 so 4 addresess per byte required
spr0 : array[4] of integer;
spr1 : array[4] of integer;
spr2 : array[4] of integer;
spr3 : array[4] of integer;
...
// sprite is 24 x 40. Need 40 bytes per shift ($28) x 4 shifts = $A0
vbmSpriteShiftR( ^@spra0, ^$a000, 2, 40, spr0 );
vbmSpriteShiftL( ^@spra0, ^$a0A0, 2, 40, spr1 );
vbmSpriteShiftR( ^@spra1, ^$a140, 2, 40, spr2 );
vbmSpriteStitch( ^$a140, ^$a0a0, 160 ); // 40 high * 4 = 160
vbmSpriteShiftL( ^@spra1, ^$a140, 2, 40, spr2 );
vbmSpriteShiftR( ^@spra2, ^$a1E0, 2, 40, spr3 );
vbmSpriteStitch( ^$a1E0, ^$a140, 160 );
vbmSpriteShiftL( ^@spra2, ^$a1E0, 2, 40, spr3 );
y := 10;
for x := 0 to 100 do
begin
vbmSetPosition2( x, y ); // position the sprite, 2 pixel increments
vbmDrawSpriteSlice( spr0, 0, 40 );
vbmNextColumn();
vbmDrawSpriteSlice( spr1, 0, 40 );
vbmNextColumn();
vbmDrawSpriteSlice( spr2, 0, 40 );
vbmNextColumn();
vbmDrawSpriteSlice( spr3, 0, 40 );
waitforraster( 0 ); // wait for raster
vbmSetPosition2( x, y ); // position the sprite, 2 pixel increments
vbmClearSpriteSlice( spr0, 0, 40 );
vbmNextColumn();
vbmClearSpriteSlice( spr1, 0, 40 );
vbmNextColumn();
vbmClearSpriteSlice( spr2, 0, 40 );
vbmNextColumn();
vbmClearSpriteSlice( spr3, 0, 40 );
end;
See also
- vbmDrawSprite8
- vbmDrawSprite16
- vbmSetPosition1 / 2 / 4