-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathspritesheet.py
More file actions
36 lines (30 loc) · 1.33 KB
/
spritesheet.py
File metadata and controls
36 lines (30 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#where this module came from
import pygame
class spritesheet(object):
def __init__(self, filename):
try:
self.sheet = pygame.image.load(filename).convert().convert_alpha()
except pygame.error, message:
print 'Unable to load spritesheet image:', filename
raise SystemExit, message
# load a specific image from a specific rectangle
def image_at(self, rectangle, colorkey=None):
# loads image from x,y,x+offset,y+offset
rect = pygame.Rect(rectangle)
image = pygame.Surface(rect.size).convert()
image.blit(self.sheet, (0, 0), rect)
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0, 0))
image.set_colorkey(colorkey, pygame.RLEACCEL)
return image
# load a whole bunch of images and return them as a list
def images_at(self, rects, colorkey=None):
# loads multiple images, supply a list of coordinates"
return [self.image_at(rect, colorkey) for rect in rects]
# load a whole strip of images
def load_strip(self, rect, image_count, colorkey=None):
# loads a strip of images and returns them as a list
tups = [(rect[0]+rect[2]*x, rect[1], rect[2], rect[3])
for x in range(image_count)]
return self.images_at(tups, colorkey)