mapeditor/tiled

Do you want to work on this issue?

You can request for a bounty in order to promote it!

TileMap.insertLayerAt() and GroupLayer.insertLayerAt() behave different #3486

juanitogan posted onGitHub

Describe the bug

TileMap.insertLayerAt() and GroupLayer.insertLayerAt() behave different with a new layer and size not set. TileMap version will resize the layer to the size of the map. GroupLayer version will leave the size at 0,0. The GroupLayer documentation says it should resize it (TileMap doc does not say).

To Reproduce

layer1 = new TileLayer("New Layer")
TileMap.insertLayerAt(0, layer1)
// versus
layer2 = new TileLayer("New Layer")
GroupLayer.insertLayerAt(0, layer2)

Expected behavior

TileMap doc:

Inserts the layer at the given index. The layer can’t already be part of a map.

GroupLayer doc:

Inserts the layer at the given index. The layer can't already be part of a map.

When adding a TileLayer to a map, the layer's width and height are automatically initialized to the size of the map (since Tiled 1.4.2).

Workaround is to set the size explicitly.

Specifications:

  • OS: Windows 10
  • Tiled Version: 1.9.2

Note that the GroupLayer doc says "When adding a TileLayer to a map". Until a layer is added to a TileMap, there's nowhere to pull a default size from, so it's left at 0. Adding a layer to a Group does not necessarily add it to a TileMap.

Or does it not set the size even when adding a grouped tile layer to a map (i.e. by adding the parent GroupLayer to a TileMap, or adding a TileLayer to a GroupLayer that is already part of a TileMap)? In that case, you may want to reword the issue.

posted by eishiya over 2 years ago

Interesting nuance in the wording but, really, I wasn't saying things should be this way or that way. I was merely pointing out (or trying to) the difference in behaviors and failure of the doc to describe them. Just trying to eliminate surprises.

But, yes, I was only working with GroupLayers that are already part of a TileMap. And, thus, the behavior was surprising that the layer did not autosize. But, as to the correctness of that versus the doc, I'll leave to others to decide.

posted by juanitogan about 2 years ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests