BigSprite
BigSprite is the beginnings of a library intended to make it easier to manipulate sprites. The purpose of BigSprite is:
- to easily combine up to 22 8x8 sprites into any size or shape you wish
once combined, the 8x8 sprites can function as one BigSprite, which can be easily moved as a unit etc.
BigSprite has built-in collision detection of other BigSprites and of background tiles using bounding boxes
You don't have to know how BigSprite works to make good use of it. Just follow these directions and use the functions as described. You can also look at hello-bs.asm as an example.
overview
The BigSprite library reserves space for 32 BigSprites located from memory location $DC00 to $DFFF.
Each BigSprite takes 32 bytes to describe. The bytes are as follows:
- 1 byte: sprite ID
the ID can be any 1-byte number you want, but should be unique for each BigSprite
since there are a maximum of 32 BigSprites, it would be possible to use 2 extra bits in this byte as flags
2 bytes: location of BigSprite in upper left hand corner on screen (x,y)
- 4 bytes: bounding boxes (lowx, lowy, highx, highy)
- 2 bytes: sprite dimensions in terms of 8x8 sprites (x # of sprites, y # of sprites)
22 bytes: list of sprites used. (must be 22 bytes even if 22 sprites aren't used)
- 1 byte: flags (not yet implemented)
- 1 byte: sprite ID
blank BigSprites are loaded with BSEMPTY (currently $ff)
for simplicity, the BigSprite library creates 32 8x8 sprites numbered 0 through 31 and sets each of these sprites to its corresponding tile number i.e. sprite 0 is loaded with tile 0, sprite 1 with tile 1, etc.
usage
create your tiles
- create tiles for your sprite using GBDT or whatever
- design your tiles using any dimensions you wish, but for simplicity export them as 8x8
it's easiest if you number your tiles for BigSprite starting with tile 0
it is easiest if there is a unique tile for every part of every BigSprite
- if a particular tile is needed more than once for your design, duplicate it
if a particular BigSprite will appear more than 1 time, duplicate all of its tiles
edit bigsprite.asm
replace the example hardcoded BigSprite descriptions at the beginning of the file with your hardcoded BigSprite descriptions
each description needs to be 32 bytes and needs to follow exactly the byte layout described above (also shown in the example descriptions inside bigsprite.asm)
edit the number of hardcoded BigSprite descriptions EQUed with HARDCODEDBSES
edit your code
add INCLUDE "bigsprite.asm" in your code after a section statement.
One good place for it might be right after INCLUDE "memory.asm" if you have that line
bigsprite.asm requires hello-sprite.inc so have the most recent version of that in your path as well
at the end of your main code initialization add
INIT_BS
this calls a macro which sets up the BigSprite system
function calls and macros in the BigSprite library
INIT_BS
Initialize the BigSprite system
- initializes sprites 0-31 and assigns them to tiles 0-31
loads hardcoded BigSprites
initializes the remaining BigSprite list as empty
- add to the end of your initialization code, after the tiles are loaded and before the main loop
SET_BS_LOC <BS ID>,<X coord>,<Y coord>
set the X and Y coords of a specified BigSprite
- input:
- BS ID can be any 8 bit number or any 8 bit register (a,b,c,d,e,h,l)
- X coord and Y coord can be any 8 bit number or any 8 bit register except h or l
- input:
call get_bs_param
get coordinates of BigSprite location or of any corner of a bounding box
- input:
a = BigSprite ID
- b = specified parameter: one of the following constants:
BB_UPPER_LEFT: upper left corner of bounding box
BB_UPPER_RIGHT: upper right corner of bounding box
BB_LOWER_LEFT: lower left corner of bounding box
BB_LOWER_RIGHT: lower right corner of bounding box
BS_LOCATION: BigSprite screen location
- output: d: x coordinate (pixels), e: y coordinate (pixels)
- input:
call BSCheck4Clison
test if 2 BigSprites are colliding
input: h = BigSprite 1 ID, l = BigSprite 2 ID
output: c flag is set if BigSprites are colliding, otherwise is reset
call bs_get_background_tile
return tile # of background tile touching specified corner of a bounding boxa = BigSprite ID
- b = specified parameter: one of the following constants:
BB_UPPER_LEFT: upper left corner of bounding box
BB_UPPER_RIGHT: upper right corner of bounding box
BB_LOWER_LEFT: lower left corner of bounding box
BB_LOWER_RIGHT: lower right corner of bounding box
- hl: Background tile map location in memory. Will always be either _SCRN0 ($9800) or _SCRN1 ($9C00)
- output: a = tile number hitting specified corner
note: in its current implementation, this routine waits for VBLANK, since it cannot read video memory at any other time. This could (should?) be rewritten at some point to instead integrate with the VBLANK interrupt.
function calls and macros associated with the BigSprite library
SetSpriteTileNum <sprite # or name>,<tile #>
set tile # of a specified spritetechnically, SetSpriteTileNum is not part of the BigSprite library, but is instead part of sprite.inc, a dependency of BigSprite. It is mentioned here because of its obvious use with the BigSprite library. By design, the BigSprite library loads sprites 0-31 with corresponding tiles 0-31. This means that sprite 0 is automatically loaded with tile 0, sprite 1 is automatically loaded with tile 1, etc. However, using SetSpriteTileNum, the sprites can be loaded with other tiles instead.
always call this macro AFTER calling INIT_BS, since INIT_BS will redefine each sprite to be associated with its current tile # as explained above.
<sprite # or name> may be either a sprite # (0,1,2,etc.) or a name of a sprite as defined by SpriteAttr in sprite.inc