Pygame TMX 文件未加载

Pygame TMX file not loading

我一直在 pygame(https://www.youtube.com/watch?v=3UxnelT9aCo&list=PLsk-HSGFjnaGQq7ybM8Lgkh5EMxUWPm2i) 从事 KidsCanCode 项目,我已经完成了所有工作。现在我尝试通过加载两种不同的平铺格式来创建关卡,但只会加载一种。即使我尝试只加载 'level2.tmx',它也不会工作。这是代码:

main.py https://drive.google.com/file/d/1deCK3QED_e8uE4oRRECtizgTFMLvwbKN/view?usp=sharing

settings.py https://drive.google.com/file/d/1LvhnJCobweFT462PPXY42_FdnSF2UGs2/view?usp=sharing

sprites.py https://drive.google.com/file/d/1FD-Uj2SjMVNG29IcK5qaLoU6RBIB5I1s/view?usp=sharing

tilemap.py https://drive.google.com/file/d/1JeYiEo-xJHJ0I16geg7jNERAC5pqEIIH/view?usp=sharing

(顺便说一句,在main.py(load_data)中,当它说加载tiled1.tmx时,应该说level2.tmx。)

错误是这样的:

TMX compression type: zstd is not supported.
cannot load
done

它仍然加载 level1.tmx,并且游戏正常进行,但我无法加载 level2.tmx,如果我尝试加载它来玩,屏幕不会加载并出现错误:

TMX compression type: zstd is not supported.
Traceback (most recent call last):
  File "C:\Users\ruben\Documents\MAX\Python\Pygame\tileyLevel\main.py", line 285, in <module>
    g.new()
  File "C:\Users\ruben\Documents\MAX\Python\Pygame\tileyLevel\main.py", line 120, in new
    self.map = TiledMap(path.join(self.map_folder, 'level2.tmx'))
  File "C:\Users\ruben\Documents\MAX\Python\Pygame\tileyLevel\tilemap.py", line 22, in __init__
    tm = pytmx.load_pygame(filename, pixelalpha=True)
  File "C:\Users\ruben\AppData\Local\Programs\Python\Python38\lib\site-packages\pytmx\util_pygame.py", line 141, in load_pygame
    return pytmx.TiledMap(filename, *args, **kwargs)
  File "C:\Users\ruben\AppData\Local\Programs\Python\Python38\lib\site-packages\pytmx\pytmx.py", line 360, in __init__
    self.parse_xml(ElementTree.parse(self.filename).getroot())
  File "C:\Users\ruben\AppData\Local\Programs\Python\Python38\lib\site-packages\pytmx\pytmx.py", line 391, in parse_xml
    self.add_layer(TiledTileLayer(self, subnode))
  File "C:\Users\ruben\AppData\Local\Programs\Python\Python38\lib\site-packages\pytmx\pytmx.py", line 962, in __init__
    self.parse_xml(node)
  File "C:\Users\ruben\AppData\Local\Programs\Python\Python38\lib\site-packages\pytmx\pytmx.py", line 1044, in parse_xml
    raise Exception
Exception

如果有人能帮助我,那就太好了。谢谢!

错误表明文件 level2.tmx 是使用压缩类型 zstd 压缩的。您的 python 安装不支持这种压缩。

如果安装 python 模块来处理这种压缩,例如模块位于: https://pypi.org/project/zstd/ 可能有用。

或者您需要将 level2.tmx 转换为与 level1.tmx

相同的格式

我想我有一个答案,但是每次我杀僵尸,错误

Traceback (most recent call last):
  File "C:\Users\ruben\Documents\MAX\Python\Pygame\tileyLevel\main.py", line 295, in <module>
    g.run()
  File "C:\Users\ruben\Documents\MAX\Python\Pygame\tileyLevel\main.py", line 155, in run
    self.draw()
  File "C:\Users\ruben\Documents\MAX\Python\Pygame\tileyLevel\main.py", line 222, in draw
    self.screen.blit(self.map_img, self.camera.apply(self.map))
  File "C:\Users\ruben\Documents\MAX\Python\Pygame\tileyLevel\tilemap.py", line 49, in apply
          return entity.rect.move(self.camera.topleft)
AttributeError: 'TiledMap' object has no attribute 'rect'

出现。我不知道这是为什么。我知道我应该只编辑答案来做到这一点,但我无法做到这一点。我需要两个答案。文件没有太大变化,但它们在这里:

settings.py https://drive.google.com/file/d/1ziel23c9GkB9kzcVOcrqiCVMq-RtfC2q/view?usp=sharing

tilemap.py https://drive.google.com/file/d/12-Xh7P7llm5nGPqGt_CLkFbzU8LfWtBK/view?usp=sharing

main.py https://drive.google.com/file/d/1gUTQ30GI2bK6oUalA4T9hUwffphE4sun/view?usp=sharing

sprites.py https://drive.google.com/file/d/1EhHRkEzAJp6spKFMv-ar-jMSOy79DSjc/view?usp=sharing

level3.tmx(你已经有level1和level2了) https://drive.google.com/file/d/1E4FrrSNt6748mar77gV8nztU25z3oSfI/view?usp=sharing

level4.tmx https://drive.google.com/file/d/1pLB7j3rX3_YY2d_nv92zfZnXJSGoeoJa/view?usp=sharing

level24.tmx(是0级,但我选择写level24,因为我不太可能有24级。我懒得改名字。) https://drive.google.com/file/d/1pLB7j3rX3_YY2d_nv92zfZnXJSGoeoJa/view?usp=sharing

Dungeons.tmx https://drive.google.com/file/d/1dGvWZ8EKf2WZ71k3RORTczjUIxRebec0/view?usp=sharing

如果您能回答这个问题或问题,那就太好了。