Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Get total number of sprites

Author
Message
Peppivankokki
13
Years of Service
User Offline
Joined: 19th Aug 2011
Location:
Posted: 29th Aug 2011 12:36
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:



If anyone has a better solution, please let me know...
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 30th Aug 2011 18:50
I think your solution is good. I'm not sure why you would need to discover the total frames anyway. Because when you make the sprite, you have to know the frames....

The fastest code is the code never written.
Peppivankokki
13
Years of Service
User Offline
Joined: 19th Aug 2011
Location:
Posted: 31st Aug 2011 20:01
Obviously you know the number of frames, when you create a sprite. But I want to make the functions as generic as possible, such that you can apply them to any sprite, without having to pass the number of frames as an argument.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 7th Sep 2011 00:17
In that case, I think having a known to start with would be beneficial. If you have a specific size for your sprite, you could use a math function to determine the total.
For instance, if you had the sprite size to be 32x32 then, you could use this formula:
int NF=dbGetImageWidth(img)/32*(dbGetImageHeight(img)/32));
This would only work if the image is a solid square or rectangle.

The fastest code is the code never written.

Login to post a reply

Server time is: 2024-11-19 08:48:42
Your offset time is: 2024-11-19 08:48:42