I'm trying to load a tmx map but an error keeps popping out.
This line causes the error:
self.tilemap = = tmx.load('map1.tmx', screen.get_size())
import pygame
import tmx
class Game(object):
def main(self, screen):
clock = pygame.time.Clock()
self.tilemap = tmx.load('map1.tmx', screen.get_size())
self.sprites = tmx.SpriteLayer()
start_cell = self.tilemap.layers['triggers'].find('player')[0]
self.player = Player((start_cell.px, start_cell.py), self.sprites)
self.tilemap.layers.append(self.sprites)
while 1:
dt = clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
return
self.tilemap.update(dt / 1000., self)
self.tilemap.draw(screen)
pygame.display.flip()
This is the traceback:
Traceback (most recent call last):
File "C:/Users/snapg/PycharmProjects/PythonBasics/Poptropica like Game/Starting Physics.py", line 78, in <module>
Game().main(screen)
File "C:/Users/snapg/PycharmProjects/PythonBasics/Poptropica like Game/Starting Physics.py", line 56, in main
self.tilemap = tmx.load('map1.tmx', screen.get_size())
File "C:\Users\snapg\PycharmProjects\PythonBasics\Poptropica like Game\tmx.py", line 835, in load
return TileMap.load(filename, viewport)
File "C:\Users\snapg\PycharmProjects\PythonBasics\Poptropica like Game\tmx.py", line 711, in load
tilemap.tilesets.add(Tileset.fromxml(tag))
File "C:\Users\snapg\PycharmProjects\PythonBasics\Poptropica like Game\tmx.py", line 67, in fromxml
return cls.fromxml(tileset, firstgid)
File "C:\Users\snapg\PycharmProjects\PythonBasics\Poptropica like Game\tmx.py", line 80, in fromxml
tileset.add_image(c.attrib['source'])
File "C:\Users\snapg\PycharmProjects\PythonBasics\Poptropica like Game\tmx.py", line 87, in add_image
image = pygame.image.load(file).convert_alpha()
pygame.error: Couldn't open ../Documents/Map1.png
In "../Documents" there is no file named Map1.png (this file is the tile set and it stays the same location and name even after I changed its name and moved it to that location and none of that worked).