Skip to main content

User login

What is OpenID?
  • Log in using OpenID
  • Cancel OpenID login
  • Create new account
  • Request new password
Register
  • Home
  • Browse
    • 2D Art
    • 3D Art
    • Concept Art
    • Textures
    • Music
    • Sound Effects
    • Documents
    • Featured Tutorials
  • Submit Art
  • Collect
    • My Collections
    • Art Collections
  • Forums
  • FAQ
  • Leaderboards
    • All Time
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
    • Weekly
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
  • ❤ Donate
General Discussion

How can we extract images from spritesheets?

pisceswolf96
Friday, March 27, 2015 - 11:49
pisceswolf96's picture

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

 

  • Log in or register to post comments
Boogle
joined 10 years 3 months ago
Friday, March 27, 2015 - 13:57

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.

 

  • Log in or register to post comments
pisceswolf96
joined 10 years 3 months ago
Friday, March 27, 2015 - 14:02
pisceswolf96's picture

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?

  • Log in or register to post comments
Boogle
joined 10 years 3 months ago
Friday, March 27, 2015 - 14:28

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.

 

  • Log in or register to post comments
surt
joined 16 years 1 week ago
Friday, March 27, 2015 - 16:35
surt's picture

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.

  • Log in or register to post comments
pisceswolf96
joined 10 years 3 months ago
Saturday, March 28, 2015 - 00:23
pisceswolf96's picture

Thanks, man.

  • Log in or register to post comments