forked from ismailhasannnnnn/PyMario
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspritesheet.py
More file actions
30 lines (22 loc) · 941 Bytes
/
spritesheet.py
File metadata and controls
30 lines (22 loc) · 941 Bytes
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
import pygame as pg
class SpriteSheet:
def __init__(self, filename):
try:
self.sheet = pg.image.load(filename).convert_alpha()
except pg.error as e:
print("Unable to load spriteshet")
raise SystemExit(e)
def image_at(self, rect, colorKey = None):
rect = pg.Rect(rect)
image = pg.Surface(rect.size, pg.SRCALPHA)
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, pg.RLEACCEL)
return image
def images_at(self, rects, colorKey = None):
return [self.image_at(rect, colorKey) for rect in rects]
def load_strip(self, rect, image_count, colorKey = None):
tups = [(rect[0]+rect[2]*x, rect[1], rect[2], rect[3]) for x in range(image_count)]
return self.images_at(tups, colorKey)