-
Notifications
You must be signed in to change notification settings - Fork 0
/
spritesheet.py
32 lines (28 loc) · 1.24 KB
/
spritesheet.py
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
import pygame
class spritesheet(object):
def __init__(self, filename):
try:
self.sheet = pygame.image.load(filename).convert()
except pygame.error :
print ('Unable to load spritesheet image:', filename)
#raise SystemExit(message)
# Recupere une image grace a un Rect
def image_at(self, rectangle, colorkey = None):
# Recupere toute l'image
rect = pygame.Rect(rectangle)
image = pygame.Surface(rect.size).convert()
# Recupere l'image en particulier & applique la colorkey
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
# Recupere plusieurs images grace a des Rects
def images_at(self, rects, colorkey = None):
return [self.image_at(rect, colorkey) for rect in rects]
# Charge une bande d'image,
def load_strip(self, rect, image_count, colorkey = None):
# Recupere les Rects des images pour les passer dans images_at
tups = [(rect[0]+rect[2]*x, rect[1], rect[2], rect[3]) for x in range(image_count)]
return self.images_at(tups, colorkey)