Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/MAFH2/Spritesheet.py
diff options
context:
space:
mode:
Diffstat (limited to 'MAFH2/Spritesheet.py')
-rw-r--r--MAFH2/Spritesheet.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/MAFH2/Spritesheet.py b/MAFH2/Spritesheet.py
new file mode 100644
index 0000000..ddb18a8
--- /dev/null
+++ b/MAFH2/Spritesheet.py
@@ -0,0 +1,31 @@
+import pygame
+
+class Spritesheet:
+ """
+ Class from http://www.scriptedfun.com/transcript-2-using-sprite-sheets-and-drawing-the-background/
+
+ This class can be used to seporate images from the sprite sheet
+ """
+ def __init__(self, filename):
+ self.sheet = pygame.image.load(filename).convert()
+
+ def imgat(self, rect, myColorKey = None):
+ rect = pygame.Rect(rect)
+ image = pygame.Surface(rect.size).convert()
+ if myColorKey == None: myColorKey = image.get_at((0,0))
+ image.set_colorkey(myColorKey)
+ image.blit(self.sheet, (0, 0), rect)
+ return image
+
+ def imgsat(self, rects, myColorKey = None):
+ imgs = []
+ for rect in rects:
+ imgs.append(self.imgat(rect, myColorKey))
+ return imgs
+
+ def img_extract( self, cols, rows, width, height, myColorKey = None):
+ rect_list = []
+ for y in range(0, rows):
+ for x in range(0, cols):
+ rect_list.append( (width*x, height*y, width, height,) )
+ return self.imgsat( rect_list, myColorKey) \ No newline at end of file