I'm writing some convenient functions for 2d sprites (such as collision detection). For this purpose it is useful to get the total number of frames in a sprite. Is there a standard function for this purpose, that I'm not aware of?
I composed this function to return the number of frames in a sprite:
int getSpriteFrameCount(int sprite_id)
{
if (dbSpriteExist(sprite_id))
{
// I'm not sure why the image get's messed up, but I have to remeber the current image number and reset it at the end of this function
int img_id = dbSpriteImage(sprite_id);
// Remember the current frame number, it needs to be reset at the end of this function
int start_frame = dbSpriteFrame(sprite_id);
int next_frame = start_frame;
do
{
dbSetSpriteFrame(sprite_id, next_frame);
next_frame++;
} while ((next_frame - 1) == dbSpriteFrame(sprite_id));
dbSetSpriteFrame(sprite_id, start_frame);
// Again, I don't know why the image get's messed up, but I need to reset it here:
dbSetSpriteImage(sprite_id, img_id);
return next_frame - 3;
}
return 0;
}
If anyone has a better solution, please let me know...