Unevenly Spaced Sprite Sheets

Started by
6 comments, last by yewbie 14 years ago
How do you deal with sprite sheets that are not perfectly spaced? In every 2D animation tutorial I have seen, they are dealing with a sprite sheet that fits into the same sized rectangle, but the ones I am using are spaced haphazardly. Is there any way to have the code solve it by creating variably sized rectangles around each sprite, or do I just have to go and manually assign the rectangle boundaries or use an image editor? I was thinking about possibly something to search for the start and end of a sprite based on searching for the background color, but I have no idea how to implement something like that.
Advertisement
One thing you could do (depending on what color bit your using), is use the boundary around the cells and each boundary signifies a different size?

IE: a 40x40 pixel square would have a boundary of say color 40/65365
and a 100x100 box would have a boundary of 100/65365
or whatever you use for your colors (be it 16 bit or whatever)

and to make it easier (albeit harder to work with) you could just have a single table of cells to make it easier to read like this

x
x
x
x
x

instead of the standard
xxxxxx
xxxxxx
xxxxxx


so it would end up being something like

 ____|    ||    ||--------||        ||        ||        ||--------||  ||--|


and then by just reading that color value you would know what size of a box to read, although this won't work with uneven size things.

Also im sure there are way better ways of doing this, but just something that popped to mind.
That would work well, but unfortunately I am using sprite sheets made by other people that I grabbed off the internet, and they are all spaced by the original creators. I am looking for a way to cope with that within the actual code instead of manipulating the sprite sheet. I have been thinking about this and I thought it would generally go something like:

sprite sprites[10]; where sprite is a class
int numFound = 0;

for(int y = 0; y < ImageHeight; y++) {
for(int x = 0; x < ImageWidth; x++) {
if(pixel matches the background color) {
if (next pixel matches the background color) {
continue;
}
else {
//It would mean the next pixel is part of a sprite
sprites[numFound].x = x;
sprites[numFound].y = y;
numFound += 1;
}
}
}

but what I do not understand is how to get the color information from a specific pixel.
I think it would be better to make a very simple editor that allows you to draw rectangles around the sprites and have the editor spit out a data file (xml?) that contains all rectangles and identification of the frames.

If the sprite sheets are beyond your control, that would be safer than trusting background colors (whatif a single frame contains two objects?)
Quote:Original post by kevin_06s
How do you deal with sprite sheets that are not perfectly spaced?

...

I was thinking about possibly something to search for the start and end of a sprite based on searching for the background color, but I have no idea how to implement something like that.

About a year ago, I used exactly that method, and coded up an example of it for fun. Conviently, I wrote it in the same API you are using (SDL), so all you need to do is add two files to your code, and you can load both evenly sized tiles, and unevenly sized tiles.

Link to old post with code and images

If you are interested in how it works, the functions are heavily commented and easy to read.
I'm interested too.

Now I'm using an old program that works very well, it finds auto-magically all the sprites in a sprite sheet and let you edit coordinates and the hotspot (very very useful for any decent 2d game).
But... it has some bugs, its user interface is not top notch and I haven't the source... I would love to see this problem solved once for all with a "super" sprite editor.

Someone knows about a good opensource project targeting this?
You should be able to read directly from it however it's laid out. I actually work like you describe through choice as the less rules you put on the artist the better.

Just make a rendering routine that accepts a rect for the source and give it the numbers. If you tell the artist to at least put similar stuff (such as a set of running animations) next to each other, then you can easily write code to build the rectangles for you.
------------------------------Great Little War Game
Very nice Servant of the Lord, something like that almost makes me want to switch to SDL =p

This topic is closed to new replies.

Advertisement