pytmx icon indicating copy to clipboard operation
pytmx copied to clipboard

Layer groups do not appear to be working

Open dawsoneliasen opened this issue 5 years ago • 3 comments

When I try to use a .tmx with all layers stored in layer groups, I get this error

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytmx/pytmx.py", line 682, in get_layer_by_name
    return self.layernames[name]
KeyError: 'background'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "convoke/world.py", line 81, in <module>
    Scene(landscape_path).run()
  File "convoke/world.py", line 34, in __init__
    bg_layer = scene_data.get_layer_by_name('background')
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytmx/pytmx.py", line 686, in get_layer_by_name
    raise ValueError
ValueError

I tried printing the value in .layernames and .layers, both were empty. I changed the map to not use layer groups at all, and PyTMX recognized all of the layers. Seems like it is failing to recognize layer groups.

dawsoneliasen avatar May 08 '20 00:05 dawsoneliasen

Thanks for the bug report. I think you are probably correct, Layer Groups are probably not recognized. I don't recall having made a feature for them.

bitcraft avatar May 08 '20 18:05 bitcraft

Ah, there are some misleading points in the README, then. Here is an example:

# get a layer by name
layer_or_group = tiled_map.get_layer_by_name("base layer")

# TiledMap.layers is a list of layers and groups
layer = tiled_map.layers[layer_index_number]

This sounds like I can access layer groups the same way I access layers.

dawsoneliasen avatar May 09 '20 14:05 dawsoneliasen

Layer groups are not supported right now, so they will not be included anywhere.

bitcraft avatar Nov 16 '20 16:11 bitcraft