6
votes

Argh!!! I am new to this whole python thing and the only way I know how to make a "animation" is by using individual pictures (as in 1 pic per file). Well, I got a sprite sheet that is perfect for what I need, only problem is that it is a sprite sheet. I don't want to spend the time, cropping each individual sprite out.

More information, I am new to python and pygame. Just started learning the language back in August is a class that is moving very slowly...so if you could explain what you are doing so I can do it for future projects I would really appreciate it. I am also using Python 3.2, if that makes a difference because I am pretty sure there are some syntax differences between Python 2 and Python 3.

THANKS!!!! This will help me a lot.

1
there is a nice spritesheet class that is great imho(and easy to understand) ... pygame.org/wiki/Spritesheet - Joran Beasley
Post some of your code that's giving you problems? Also some more explanation what you're trying to do would be good (personally, I've got absolutely no idea as to what a sprite sheet is). - Aleksander Lidtke
In the future, you might want to try Google, or the documentation. Searching either Google or the pygame wiki for "pygame sprite sheet", or your entire question title, turns up the link Joran and I found, as the first hit. Doing that would avoid the need for you to write those two extra paragraphs. And Google can answer in 0.19 seconds instead of taking 3 minutes like a human. Plus, we may end up with your SO question beating the more useful wiki page for future searchers, slowing everyone down. - abarnert

1 Answers

4
votes

It really isn't very hard to do… but the best sample code I found in a quick search is also a usable library that does the work for you: spritesheet, right from the pygame wiki.

So, you can start off by just using that. I'd give you an example tailored to your use case, but you haven't given us any idea what your code looks like or what you want to do, so I can't possibly give you anything better than is already on that page, so:

import spritesheet
...
ss = spritesheet.spritesheet('somespritesheet.png')
# Sprite is 16x16 pixels at location 0,0 in the file...
image = ss.image_at((0, 0, 16, 16))
images = []
# Load two images into an array, their transparent bit is (255, 255, 255)
images = ss.images_at((0, 0, 16, 16),(17, 0, 16,16), colorkey=(255, 255, 255))
…

Meanwhile, you can read the (very simple) code in that spritesheet class to understand how it works.