HaxeFlixel / flixel-addons

Additional classes for HaxeFlixel
171 stars 139 forks source link

[Feature] Add support for tiled grouped layers #319

Closed guifes closed 4 years ago

guifes commented 6 years ago

That's about it

Gama11 commented 6 years ago

I'm not very familiar with the details of Tiled's map format, got any more details about this? Or are you working on a PR anyway? :)

elliocheerio commented 5 years ago

Tiled layers are loaded into the TiledMap.layers property, an array of TiledLayers.
Grouped layers in Tiled allows nesting layers into groups (visually represented in a folder hierarchy). Currently TiledMap.layers only loads the direct layers from Tiled and not the nested layers from groups.

I see two solutions:

  1. Recursively load all layers of a grouped layer directly into TiledMap.layers.
    TiledMap.layers would remain a single dimension Array<TiledLayer>.

  2. Recursively load all layers of a grouped layer nested into TiledMap.layers. TiledMap.layers would become a multiple dimension array.

I think the first solution is more straightforward, and layerParent / layerChild properties could be added to preserve the hierarchy. Thoughts? :)

guifes commented 5 years ago

I've have created a PR https://github.com/HaxeFlixel/flixel-addons/issues/319.

I made it trying to change as little as I could from the original code base. Tiled kinda treats groups as layers so I created a TiledGroupLayer, added another type to TiledLayers Type named GROUP, and when loading layers I check for group layer and add all it's internal layers recursively. I forwarded the noLoadHash to TiledGroupLayer so that it could check for "no load layers" as well.

I went with "2" (@elliocheerio ) because that produces a result more close to what I would expect from the structure of the tiled xml. But I'm not against making nested layers redundantly accessible from TileMap's layers and layerMap directly.

The PR covers my needs, but feel free to edit and add anything that might be missing.