SDL Image Clipping Software (?)
This isn't a programming question before any of you freak out on me. :D
For any of you who use SDL, you know that using sprite sheets is an awesome way to keep all of your animation images in the same file, saving space and time, blah blah blah.
What I need is a program that will give me the x and y coordinates in the image in the style that SDL reads them in.
Photoshop CS3 has a tool that does it, but...well its freaking time consuming to sit there and get the coordinates for a character with over 200+ movements. I have about 25 entities I'm gonna need to make clips for and I'd love to know if anyone knows a faster way to do this?
In return I'll give you my undying affection. :D
No seriously, I need help. Anyone got any suggestions?
--------- ApochPiQ : <Serious Grammar Nazi Pet Peeve> FFS guys, it's spelled "dying". That is all. </Serious Grammar Nazi Pet Peeve>
Why not make one? It should be as easy as loading a sprite sheet, and going through each pixel in the sprite sheet until you find a pixel that doesn't match the sprite sheet background color*. That gives you the origin.
Once you find that pixel, remember that point, and start checking the pixels vertically from that point until you hit the tileset background color again (or the end of the image, vertically). That gives you the height.
Return to the origin, and count pixels horizontally until you hit the background color again (or the end of the image, horizontally). That gives you the width. Save the completed clipping rectangle into a vector or something.
Then, draw a rectangle over the image you just found, the same color as the background of the sprite sheet, 'erasing' it. You don't save the sprite sheetwhen you are done, so it wont erase your actual sprite sheet.
Continue going through each pixel in the sprite sheet from where you left off, and repeat the process the next time you hit another pixel that doesn't match the background. When finished, your vector will hold a SDL_Rect of each sprite in your sprite sheet, which you can then write to a file, and load in your game alongside your sprite sheet.
This will work even if your sprites aren't the same sizes. There are only to caveats:
1) The background color of the sprite sheet cannot be used in any of the sprites. (This is why you need to make the colorkey a different color)
2) It requires that your sprites are separated by at least one pixel.
Unless I misunderstood what you were doing, this should work fine for you. Sometimes, if it's a small thing, it's quicker to make it yourself, than to searching for programs that have that feature.
*Make sure your background color is a different color than your sprites' colorkeys.
Once you find that pixel, remember that point, and start checking the pixels vertically from that point until you hit the tileset background color again (or the end of the image, vertically). That gives you the height.
Return to the origin, and count pixels horizontally until you hit the background color again (or the end of the image, horizontally). That gives you the width. Save the completed clipping rectangle into a vector or something.
Then, draw a rectangle over the image you just found, the same color as the background of the sprite sheet, 'erasing' it. You don't save the sprite sheetwhen you are done, so it wont erase your actual sprite sheet.
Continue going through each pixel in the sprite sheet from where you left off, and repeat the process the next time you hit another pixel that doesn't match the background. When finished, your vector will hold a SDL_Rect of each sprite in your sprite sheet, which you can then write to a file, and load in your game alongside your sprite sheet.
This will work even if your sprites aren't the same sizes. There are only to caveats:
1) The background color of the sprite sheet cannot be used in any of the sprites. (This is why you need to make the colorkey a different color)
2) It requires that your sprites are separated by at least one pixel.
Unless I misunderstood what you were doing, this should work fine for you. Sometimes, if it's a small thing, it's quicker to make it yourself, than to searching for programs that have that feature.
*Make sure your background color is a different color than your sprites' colorkeys.
I was afraid someone would say this :D
Well I guess I'd better figure out how to write that program. Thanks for the pseudo-guide though. I'll just have to figure out how to write this.
Lazy Foo's SDL tutorials had a function that was supposed to do this, but when I tried it, my program crashed.
Well I guess I'd better figure out how to write that program. Thanks for the pseudo-guide though. I'll just have to figure out how to write this.
Lazy Foo's SDL tutorials had a function that was supposed to do this, but when I tried it, my program crashed.
--------- ApochPiQ : <Serious Grammar Nazi Pet Peeve> FFS guys, it's spelled "dying". That is all. </Serious Grammar Nazi Pet Peeve>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement