Get sprites sizes and positions from an image

Started by
4 comments, last by Gangi 12 years, 8 months ago
Hello!!

I looked in the forum but I didn't find anybody with the same problem I have so I think I should ask.

This is my situation: I have an image with a lot of sprites of the same character inside and I want to use this image to create an animation of the character in my game. In other images I used, all the sprites were equally spaced and had the same size so it was easy to locate them inside the image. Now my problem is that almost every sprite has a different size and position so it's very tedious to get the position of the sprites. Since I have 7 images with like a 50 sprites inside of each of them getting the position manually is not an option.

I thought to make a program to detect the size and position of the sprites ( I did something similar to detect shapes using the Matlab image toolkit so it's possible). But I think there's no reason to reinvent the wheel, I suppose somebody should have the same problem sometime. How did you solved it? Is there any application that makes this?

Thanks!!
Advertisement
I'm not sure if I'm understanding right. Do you mean that all of the sprites are different in size, and at random positions? Or do you mean you have multiple textures/animation sprites, each with their own size, and location?

For example:

If you have a character with a run animation and also a jump animation on the same sprite sheet, each with 5 frames. Are the 5 frames for the run animation all the same size, and are next to each other in order, while the jump animation has a different 5 frames, all with the same size, except it is a different size from the run animation, but each are in order? If so, thats a relatively easy fix.

I had something like this before, however the way I structured my animating classes fixed it. Esentially, I had a base Animating class with drawing functions/methods, that was passed in an 'Animation' variable (a seperate class), and the 'Animation' class had its own name for the animation, starting location of the first sprite, number of frames, size, etc. and various other intuitive functions that determined the frames to be used. And all these animation variables were declared inside the Player class (hard coded).

This was in XNA, so I'm not sure if it will work for whatever program your using.

Best of luck.
Taking less of a programming approach, I took out a picture editor and put everything where I wanted it. I think it'll become more difficult to make a program to contain the chaos rather than to manually contain it yourself. Unifying your artwork into a specific format will cut down the processing time/take away those bugs that can creep in from when something unexpected arises in another file. I don't know much about picture editors but if you found one with a grid I'm sure it'd help out a lot. (the alternative if making your own grid)
The best solution is to create a descriptor file that contains the data (coordinates, width/height, etc) of these sprites. However, that means you would need a tool to generate this for you. You can create them yourself, or I don't know if there's a program out there that does it for you for free. At my previous company, this is the approach it took for its inhouse animation suite. It's flexible as the image can still be in its native format (png), and the descriptor file can describe various information. The file encodes frames, animations, offsets, collision boxes, and other properties custom-defined by developers.

Another solution is to draw lines separating these sprites. You'd then look for these lines in your loading code, and take the sprites individually. It's less flexible and increases the file size, but doable even with Paint.
I usually just make a program that opens the image and splits that image into each individual frame, then you put it back together in the order you want with the same program. Though at that time I didn't have it adjustable for different sprite sizes. I have seen sheets like that though, it looks like there are random in placement, but they usually aren't. Post the image.

Get a program called Mappy or Winmappy, something for editing maps used a lot with C++/Allegro Library, at least I used it a lot. it is able to split tiles then you can delete certain tiles and save what is left. Quite sure you can figure out how to put them back together with the same program so I wont explain it. Very easy to use.

Sprite Creator 3 VX & XP

WARNING: I edit my posts constantly.


I'm not sure if I'm understanding right. Do you mean that all of the sprites are different in size, and at random positions? Or do you mean you have multiple textures/animation sprites, each with their own size, and location?

For example:

If you have a character with a run animation and also a jump animation on the same sprite sheet, each with 5 frames. Are the 5 frames for the run animation all the same size, and are next to each other in order, while the jump animation has a different 5 frames, all with the same size, except it is a different size from the run animation, but each are in order? If so, thats a relatively easy fix.

I had something like this before, however the way I structured my animating classes fixed it. Esentially, I had a base Animating class with drawing functions/methods, that was passed in an 'Animation' variable (a seperate class), and the 'Animation' class had its own name for the animation, starting location of the first sprite, number of frames, size, etc. and various other intuitive functions that determined the frames to be used. And all these animation variables were declared inside the Player class (hard coded).

This was in XNA, so I'm not sure if it will work for whatever program your using.

Best of luck.


No, the frames are of differents size so the problem is to locate them easily. In other games I did something like this to locate the frames in the image: next_frame.x = prev_frame.x + width. But now I can't because each frame has a different size.



Taking less of a programming approach, I took out a picture editor and put everything where I wanted it. I think it'll become more difficult to make a program to contain the chaos rather than to manually contain it yourself. Unifying your artwork into a specific format will cut down the processing time/take away those bugs that can creep in from when something unexpected arises in another file. I don't know much about picture editors but if you found one with a grid I'm sure it'd help out a lot. (the alternative if making your own grid)


Yes, that's a good idea. I'm looking for an sprite editor program, until now I've found:

- Sprite Vortex: This program locates (x,y,width and height) all the frames in an image and print the results in a XML file. Just what I want!! It's a pity it's only for windows.
- Texture Packer
- Sprite buddy

Thanks for all your answers!!

This topic is closed to new replies.

Advertisement