Pygame TMX file not loading

352 Views Asked by At

I have been working on a KidsCanCode project in pygame(https://www.youtube.com/watch?v=3UxnelT9aCo&list=PLsk-HSGFjnaGQq7ybM8Lgkh5EMxUWPm2i) and I've finished everything. Now I'm trying to create levels by loading two different tiled formats, but only one will load. Even if I try just loading 'level2.tmx', it won't work. Here is the code:

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

(By the way, in main.py(load_data), when it says to load tiled1.tmx, it should say level2.tmx.)

The error is this:

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

It still loads level1.tmx, and the game goes on normally, but I cannot load level2.tmx, and if I try loading that to play, the screen does not load and it gives an error:

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

If someone can help me, that would be great. Thanks!

2

There are 2 best solutions below

2
Patrick Mackinlay On BEST ANSWER

The error indicates that the file, level2.tmx, is compressed with compression type zstd. This kind of compression is not supported by your python install.

If you install a python module to handle this kind of compression, such as the module at: https://pypi.org/project/zstd/ It might work.

Alternatively you need to convert level2.tmx to the same format as level1.tmx

1
Max On

I think I have an answer, but every time I kill the zombie, the error

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'

appears. I don't know why this is. I know I should just edit the answer to do this, but there is no way I can do that. I need both the answers. The files are not too changed, but here they are:

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(you already have level1 and 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(It's a level 0, but I chose to write level24 instead, because it's not likely I'll have 24 levels. I can't be bothered to change the name.) https://drive.google.com/file/d/1pLB7j3rX3_YY2d_nv92zfZnXJSGoeoJa/view?usp=sharing

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

This would be great if you could answer either this, or the question.