-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathImageData.py
44 lines (28 loc) · 1.53 KB
/
ImageData.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
33
34
35
36
37
38
39
40
41
42
43
44
import pygame,sys
class ImageData:
def __init__(self):
self.textures = dict()
self.spriteRects = dict()
def loadTexture(self, dictionaryEntry, textureFilename, colorKey = None):
try:
#completeName = os.path.join('images',textureFilename)
if colorKey == -1:
texture = pygame.image.load(textureFilename)
texture.set_colorkey(texture.get_at((0,0)))
sheetRect = texture.get_rect()
self.textures[dictionaryEntry] = [texture,sheetRect]
self.spriteRects[dictionaryEntry] = [sheetRect] # Sprite 0 = whole page
#print "Successfully loaded texture file '%s' (%s)."%(textureFilename,str(sheetRect))
else:
texture = pygame.image.load(textureFilename)
sheetRect = texture.get_rect()
self.textures[dictionaryEntry] = [texture,sheetRect]
self.spriteRects[dictionaryEntry] = [sheetRect] # Sprite 0 = whole page
#print "Successfully loaded texture file '%s' (%s)."%(textureFilename,str(sheetRect))
except:
print "Failed to load texture file '%s'!"%textureFilename
return
def assignTexture(self, dictionaryEntry, surface):
sheetRect = surface.get_rect()
self.textures[dictionaryEntry] = [surface,sheetRect]
self.spriteRects[dictionaryEntry] = [sheetRect]