diff options
author | olpc <olpc@xo-10-A7-93.localdomain> | 2010-07-13 15:15:38 (GMT) |
---|---|---|
committer | olpc <olpc@xo-10-A7-93.localdomain> | 2010-07-13 15:15:38 (GMT) |
commit | 7190dc1e75e8072f4d798230de78407983da1085 (patch) | |
tree | 1bcc1deb8f0036a206db61058557d2f4adaab76c /DrawableObjectTests/Spritesheet.py | |
parent | 64268c8dadef7166aa8321fa79b57df569f69cb4 (diff) |
Adding the current versions of DrawableObject and its sub classes
Diffstat (limited to 'DrawableObjectTests/Spritesheet.py')
-rwxr-xr-x | DrawableObjectTests/Spritesheet.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/DrawableObjectTests/Spritesheet.py b/DrawableObjectTests/Spritesheet.py new file mode 100755 index 0000000..a16226c --- /dev/null +++ b/DrawableObjectTests/Spritesheet.py @@ -0,0 +1,29 @@ +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):
+ rect = pygame.Rect(rect)
+ image = pygame.Surface(rect.size)#.convert()
+ image.blit(self.sheet, (0, 0), rect)
+ return image
+
+ def imgsat(self, rects):
+ imgs = []
+ for rect in rects:
+ imgs.append(self.imgat(rect))
+ return imgs
+
+ def img_extract( self, cols, rows, width, height ):
+ 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)
\ No newline at end of file |