pygame.error:无法打开../Documents/Map1.png

时间:2017-09-22 11:50:54

标签: python error-handling pygame tmx

我正在尝试加载tmx地图,但错误不断弹出。 此行导致错误: 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()

这是追溯:

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

在“../Documents”中没有名为Map1.png的文件(此文件是图块集,即使在我更改其名称并将其移动到该位置后,它仍保持相同的位置和名称)。

0 个答案:

没有答案