Skip to content

title: "vbmDrawSpriteSliceE" description: TRSE built-in method (from IDE help)


vbmDrawSpriteSliceE

Systems: VIC20
Parameters: a, b, b


vbmDrawSpriteSliceE( [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 using an EOR operation. The EOR operation will merge the sprite with the bitmap without destroying the bitmap, but it will look 'noisy' when pixels overlap. The way EOR works is:

  • If both the sprite and bitmap have no pixel - no pixel is drawn
  • If the sprite has a pixel but the bitmap does not - a pixel is drawn
  • If the bitmap has a pixel but the sprite does not - a pixel is drawn
  • If both the sprite and the bitmap has a pixel - a pixel is cleared

A side effect of this is that EOR can be used to both draw and remove the sprite without destroying what was already on the bitmap. When a sprite overlaps other pixels, the pxiel will clear which will look a bit noisy, but when drawn again, the sprite is removed and previous pixels restored. See example below.

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 // draw a large sprite vbmSetPosition2( x, y ); // position the sprite, 2 pixel increments vbmDrawSpriteSliceE( spr0, 0, 40 ); vbmNextColumn(); vbmDrawSpriteSliceE( spr1, 0, 40 ); vbmNextColumn(); vbmDrawSpriteSliceE( spr2, 0, 40 ); vbmNextColumn(); vbmDrawSpriteSliceE( spr3, 0, 40 ); waitforraster( 0 ); // wait for raster // drawing the large sprite again at the same position 'wipes' it out, restoring anything // prevuiously on the bitmap vbmSetPosition2( x, y ); // position the sprite, 2 pixel increments vbmDrawSpriteSliceE( spr0, 0, 40 ); vbmNextColumn(); vbmDrawSpriteSliceE( spr1, 0, 40 ); vbmNextColumn(); vbmDrawSpriteSliceE( spr2, 0, 40 ); vbmNextColumn(); vbmDrawSpriteSliceE( spr3, 0, 40 ); end;

See also

  • vbmDrawSprite8
  • vbmDrawSprite16
  • vbmSetPosition1 / 2 / 4