0

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).

skrx
  • 19,980
  • 5
  • 34
  • 48
DisplayName
  • 89
  • 1
  • 2
  • 12
  • Is the script running in the same working directory as where the tiled map was made? Possibly reopen the map in Tiled and re-save it so it fixes the relative paths. – mousetail Sep 23 '17 at 15:34
  • thank you for replying, I fixed the previous problem by changing the tileset.tsx file to look for the right image but now a new error appears: "zlib.error: Error -3 while decompressing data: incorrect header check" – DisplayName Sep 24 '17 at 16:26

0 Answers0