Original Post
Alright, this has been bugging me for a couple of hours now. If i try to load an image in my main python file, it loads fine, and i can display it. However, if I try to load it from my Tile class, the image fails to load. I've tried repositioning the file to any other directory, and it just doesn't work : Is there any know problem with pygame and loading images from a class? the main.py file and the Tile.py file are in the same directory, and the image is in a data subdir. Thanks for any help load_image function
def load_image(name, colorkey=None) :
fullname = name
try:
image = pygame.image.load(fullname)
except pygame.error, message:
print "Cannot load image: ", name
raise SystemExit, message
image = image.convert()
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0, 0))
image.set_colorkey(colorkey, RLEACCEL)
return image, image.get_rect()
Tile class
class Tile :
#position is in matrix location, i.e. 1 4
def __init__(self, name, x, y):
print "Loading Tile:" , name
fullname = os.path.join("data/tiles", name);
fullname = fullname + ".tile"
file = open(fullname, "r")
self.properties = {}
for line in file.readlines():
key, value = line.split("=")
self.properties[key] = value
print key, value
self.image, self.rect = loaders.load_image("data/" + self.properties["image"])
self.rect.top = y * 16
self.rect.left = x * 16
def draw(self, screen):
screen.blit(self.image, self.rect)