Skip to content

Cannot render tiled layers that are nested within at least one group layer #892

@BloodLantern

Description

@BloodLantern

The title is pretty self-explanatory, but I'll include an example as well. This also concerns the collision layer of a TiledMapRenderer.

Suppose I have a map with the following layers:
Image

And I load that map as the following:

var mapEntity = CreateEntity("map");
var map = Content.LoadTiledMap(Nez.Content.TiledAssets.Maps.RoomTest);
var tiledMapRenderer = mapEntity.AddComponent(new TiledMapRenderer(map, "Terrain"));
tiledMapRenderer.SetLayersToRender("Terrain", "TerrainBg");

In this situation, the call to the TiledMapRenderer constructor will throw an exception because the Terrain layer is nested within the Level group layer. This can be fixed by passing null and manually setting the CollisionLayer field on the next line:

tiledMapRenderer.CollisionLayer = map.Groups["Level"].TileLayers["Terrain"];

Even though this is not an optimal solution, it works. However, when selecting which layers to render with SetLayersToRender (or SetLayerToRender), I don't think there is a solution to this problem. The reason is that you can only set either top-level layer names or top-level layer indices.

I am very new to the framework, so I might've missed something while looking for a way to fix this.
I will soon create a pull request to add a way to do this; I'm currently working on it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions