Code: Select all
void SE_SetDrawList(char **drawkeys, int numSprites) {
Object *obj;
int i;
int x = 0;
for( i = 0; i < numSprites; i++ ) {
if( (obj = Table_Get(tblObjects, drawkeys[i])) != NULL) {
drawlist[x] = *(obj->sprite);
SPR_initSprite(&drawlist[x], obj->spritedef, obj->posX, obj->posY, TILE_ATTR(PAL0, TRUE, obj->flipH, obj->flipV));
x++;
}
}
}
- This function will be used to create the initial Sprite array to pass to SPR_update. The array is initialized in another function, and I've allocated enough memory for a MAX# of sprites (5 i think). I want to then add/remove sprites to this array.
- numSprites is the number of sprites I want to draw.
- An Object holds information for an object I want to draw, such as the position, velocity, and pointers to the sprite definition and sprite (I need this for updating positions in other functions). I created a hashtable to hold different objects, and can retrieve object info from this table.
- Drawkeys is a char array, which I can add/remove keys to. I use this char array to control what sprites to add/remove for drawing. I can grab the necessary info by comparing a key to a table of Objects, and grab the Object with the right key.
- drawlist is the array of sprites I need to pass to SPR_update(), and what I'm trying to set in this function. Drawlist is declared as extern in this source file, since it is being used across multiple files. I use drawkeys to lookup the object info, grab the sprite pointer for the object, initialize the sprite, then add the sprite to my array of sprites (drawlist).
First, I don't know why this isn't working with SPR_update. I can get it to work for one sprite, if I remove the for loop and make the following change:
Code: Select all
...
drawlist = obj->sprite;
SPR_initSprite(drawlist, obj->spritedef, obj->posX, obj->posY, TILE_ATTR(PAL0, TRUE, obj->flipH, obj->flipV));
...
Also, I'm sure there are ways to optimize this code, or take another route to drawing my sprites. This is what I've come up with so far. I'm still messing around with the program, and testing out what I can do.