sp1.h says the signature for sp1_CreateSpr is:
Code: Select all
sp1_CreateSpr(void *drawf,uint16_t type,uint16_t height,int graphic,uint16_t plane)
I'm trying to work out what the 'graphic' value is for.
The sp1_AddColSpr() routine has a similar argument, which might be related? I can't find anything on that either.
I give up! What's it for?
In both calls, it's for specifying the absolute address of the graphic for that column. In sp1 you're building the sprite up in columns so the first call to sp1_CreateSpr() creates a sprite of width one column and then successive calls to sp1_AddColSpr() add more columns.
The fact that graphic is an int is suggestive and that's because there's a good way to animate sprites if the parameter is used as an offset from the sprite graphic address instead of an absolute address to the graphics. So you'll usually see 0 in there for the sp1_CreateSpr() call and then 0+column displacement for the sp1_AddColSpr() call.
When used in this way, sp1_MoveSpr*()'s frame parameter supplies the absolute address of the graphic frame you want to use so you can animate the sprite at the same time as you move it with sp1_MoveSpr*(). The graphics pointer used is the frame address from sp1_MoveSpr*() plus the graphic parameter in the sp1_CreateSpr() and sp1_AddColSpr() calls.
The other way to go is to give sp1_CreateSpr() and sp1_AddColSpr() the absolute address of frame0 of the sprite and then give sp1_MoveSpr() an offset from the frame in its frame argument to animate the sprite image. But this is less suitable for state machines (eg) controlling the sprite animation sequence where it's easier to specify a sprite image by address instead of by displacement from frame0. If you only have one spite image then giving sp1_CreateSpr() and sp1_AddColSpr() the absolute address of the graphics image does mean you can use 0 in the sp1_MoveSpr*()'s frame parameter to draw the sprite's single frame.
Code: Select all
defb 0,0,0,0,0,0,0 ; 7 pixel rows of blank, include mask if using masked sprites
column0: ; offset = 0 from first sprite image frame
; definition of first sprite column here
defb 0,0,0,0,0,0,0,0 ; 8 pixel rows of blank, include mask if using masked sprites
column1: ; offset = column1-column0 = 8*row height of sprite
; definition of second sprite column here
(similar to above)
The above is a two-column wide sprite. sp1_CreateSpr() gets 0 for its graphic param. sp1_AddColSpr() gets column1-column0 for its graphic param because its column starts that many bytes away from the first column. The next column gets a larger graphic param because its distance from column0 is larger.
Then the call to sp1_MoveSpr*() gets the absolute address of the sprite frame to use in its frame parameter. If you want to use spriteframe0, you'd pass that address. If you want to use spriteframe1, you'd pass that instead.