0

我正在尝试使用此 tmx 库https://github.com/renfredxh/tmx/blob/master/tmx.py打开一个 tmx 地图

我的 python 代码如下所示:

import tmx3
import random
import math 
import pygame
from socket import *
from pygame.locals import *
from random import randint


pygame.init()
screen = pygame.display.set_mode((1024,640))
tilemap = tmx3.load('map.tmx', screen.get_size()) 

我尝试加载的 map.tmx 包含两层。一个没有瓦片集的瓦片层和一个带有矩形的对象层。

尝试运行我的代码时出现以下错误:

Traceback (most recent call last):
  File "C:\Users\Samy\workspace\Traveler\src\implement.py", line 12, in <module>
    tilemap = tmx3.load('map.tmx', screen.get_size()) 
  File "C:\Users\Samy\workspace\Traveler\src\tmx3.py", line 848, in load
    return TileMap.load(filename, viewport)
  File "C:\Users\Samy\workspace\Traveler\src\tmx3.py", line 727, in load
    layer = Layer.fromxml(tag, tilemap)
  File "C:\Users\Samy\workspace\Traveler\src\tmx3.py", line 261, in fromxml
    data = decompress(b64decode(data)) 
zlib.error: Error -5 while decompressing data: incomplete or truncated stream

我打印了数据,结果是 b''。有谁知道这里有什么问题?

我在这里发现了同样的问题但没有得到解答: Error using tmx with pygame

4

1 回答 1

0

当我使用纯 xml 格式的 .tmx 文件时,我遇到了同样的错误。Tiled 支持 layer-data 的一些不同的数据格式。(base64-uncompressed、base64-zlib、base64-gzip、csv 和 xml)看起来这个库需要 base64-zlib 形式。

于 2014-07-22T06:56:15.367 回答