我一直在pygame中从事KidsCanCode项目(https://www.youtube.com/watch?v=3UxnelT9aCo&list=PLsk-HSGFjnaGq7ybM8Lgkh5EMxUWPm2i(,我已经完成了所有的工作。现在我试图通过加载两种不同的平铺格式来创建级别,但只有一种会加载。即使我尝试加载'level2.tmx',它也不会起作用。这是代码:
main.pyhttps://drive.google.com/file/d/1deCK3QED_e8uE4oRRECtizgTFMLvwbKN/view?usp=sharing
设置.pyhttps://drive.google.com/file/d/1LvhnJCobweFT462PPXY42_FdnSF2UGs2/view?usp=sharing
精灵.pyhttps://drive.google.com/file/d/1FD-Uj2SjMVNG29IcK5qaLoU6RBIB5I1s/view?usp=sharing
tilemap.pyhttps://drive.google.com/file/d/1JeYiEo-xJHJ0I16geg7jNERAC5pqEIIH/view?usp=sharing
(顺便说一句,在main.py(load_data(中,当它说要加载tiled1.mx时,它应该说level2.tmx。(
错误是:
TMX compression type: zstd is not supported.
cannot load
done
它仍然加载level.tmx,游戏正常进行,但我无法加载level2.tmx,如果我尝试加载它来玩,屏幕不会加载,并给出错误:
TMX compression type: zstd is not supported.
Traceback (most recent call last):
File "C:UsersrubenDocumentsMAXPythonPygametileyLevelmain.py", line 285, in <module>
g.new()
File "C:UsersrubenDocumentsMAXPythonPygametileyLevelmain.py", line 120, in new
self.map = TiledMap(path.join(self.map_folder, 'level2.tmx'))
File "C:UsersrubenDocumentsMAXPythonPygametileyLeveltilemap.py", line 22, in __init__
tm = pytmx.load_pygame(filename, pixelalpha=True)
File "C:UsersrubenAppDataLocalProgramsPythonPython38libsite-packagespytmxutil_pygame.py", line 141, in load_pygame
return pytmx.TiledMap(filename, *args, **kwargs)
File "C:UsersrubenAppDataLocalProgramsPythonPython38libsite-packagespytmxpytmx.py", line 360, in __init__
self.parse_xml(ElementTree.parse(self.filename).getroot())
File "C:UsersrubenAppDataLocalProgramsPythonPython38libsite-packagespytmxpytmx.py", line 391, in parse_xml
self.add_layer(TiledTileLayer(self, subnode))
File "C:UsersrubenAppDataLocalProgramsPythonPython38libsite-packagespytmxpytmx.py", line 962, in __init__
self.parse_xml(node)
File "C:UsersrubenAppDataLocalProgramsPythonPython38libsite-packagespytmxpytmx.py", line 1044, in parse_xml
raise Exception
Exception
如果有人能帮助我,那就太好了。谢谢
错误表明文件level2.tmx是用压缩类型zstd压缩的。您的python安装不支持这种压缩。
如果您安装了一个python模块来处理这种压缩,例如位于以下位置的模块:https://pypi.org/project/zstd/它可能会起作用。
或者,您需要将level2.tmx转换为与level1.mx 相同的格式
我想我已经有了答案,但每次我杀死僵尸时,错误
Traceback (most recent call last):
File "C:UsersrubenDocumentsMAXPythonPygametileyLevelmain.py", line 295, in <module>
g.run()
File "C:UsersrubenDocumentsMAXPythonPygametileyLevelmain.py", line 155, in run
self.draw()
File "C:UsersrubenDocumentsMAXPythonPygametileyLevelmain.py", line 222, in draw
self.screen.blit(self.map_img, self.camera.apply(self.map))
File "C:UsersrubenDocumentsMAXPythonPygametileyLeveltilemap.py", line 49, in apply
return entity.rect.move(self.camera.topleft)
AttributeError: 'TiledMap' object has no attribute 'rect'
出现。我不知道为什么。我知道我应该编辑答案来做这个,但我不可能做到。我需要两个答案。文件没有太大变化,但它们在这里:
设置.pyhttps://drive.google.com/file/d/1ziel23c9GkB9kzcVOcrqiCVMq-RtfC2q/view?usp=sharing
tilemap.pyhttps://drive.google.com/file/d/12-Xh7P7llm5nGPqGt_CLkFbzU8LfWtBK/view?usp=sharing
main.pyhttps://drive.google.com/file/d/1gUTQ30GI2bK6oUalA4T9hUwffphE4sun/view?usp=sharing
精灵.pyhttps://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
级别4.tmxhttps://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
地下城.tmxhttps://drive.google.com/file/d/1dGvWZ8EKf2WZ71k3RORTczjUIxRebec0/view?usp=sharing
如果你能回答这个或这个问题,那就太好了。