How can we extract images from spritesheets?
How can we extract images from a spritesheet? For example this one:http://opengameart.org/content/platformer-art-deluxe
I'm using pygame and want to know what are the x and y coordinate for individual sprites and the maker doesn't provide such things. Is there any special software that we can use? Thanks
I am not sure what you are after.
1) spritesheet editors - try a few free ones - google search will reveal a bunch. add the word forum and you can find people talking about them. (e.g. spritesheet editor or spritesheet editor forum)
2) Sounds to me like you actually want to know how to load this into your game, so what you might want to look at instead in texture atlas support. You can also get texture atlas programs to help you create texture atlas files, you can then use this file in game - the file contains all the information required for each of the sprites/textures inside the image.
If you want to look into the above I would perform 2 searches:
a) Search to find if there are existing libraries / code for pygame that you can use to add texture atlas support.
b) If you don't find it - ignore texture atlas - not sure you want to code this yourself?
c) If you do find texture atlas support - then go search for a texture atlas creator - just use google again. :)
Texture atlas support is pre-built into some game makers. I haven't used pygame though.
Let's consider this image:http://2.bp.blogspot.com/-DenLx5VuHhk/UPxrPfgMkYI/AAAAAAAAABo/c0m2Kmpv-R...
The value of the first frame is (0, 109.5, 73, 109.5) and the second one is (73, 109.5, 73, 109.5) and so on...
My question is how can we get these information which can be used to load them into pygame?
Do it with some maths:
img dimensions = 1095 wide x 438 wide and is 15 sprites accross, and has 4 sprites down.
Therefore each sprite is: 1095/15 = 73px wide and 438/4 = 109px down.
So... If the sprite you want is in column X and column Y (the first sprite you want starts at 0)
The sprite maths you want for your () line above is:
( X*73, Y*109, (X*73)+73, (Y*109)+109 )
so if you want the very first sprite (top left) use X=0 and Y=0 in the above and you get the first sprite.
If you want the 5th sprite accross on the 3rd row down... X=5 and Y=3 and that is your sprite.
Presuming the sprites/tiles are fixed size bounds and laid out in a regular grid, measure the bounds size (and starting offset if necessary) then index in row-major order by:
rowLength = floor((imageWidth - offsetX) / tileWidth)
row = floor(index / rowLength)
column = index % rowLength
tileX = offsetX + column * tileWidth
tileY = offsetY + row * tileHeight
Red warrior needs caffeine badly.
Thanks, man.