Skip to content

PutTileAt sid wrong if layer does not use all tilesets #5931

@christianvoigt

Description

@christianvoigt

Version

  • Phaser Version: v3.60.0 Beta 3
  • Operating system: Windows 10
  • Browser: Chrome

Description

I am using a tilemap JSON file from Tiled with three embedded tilesets ("tileset1", "tileset2", "tileset3"). I have defined a new tile layer in Tiled "MyNewLayer" and recreated it in my game with:

map.createLayer(
      "MyNewLayer",
      [tileset3],
      0,
      0
    );

If I use map.putTileAt(tileGid, x, y, false, myNewLayer) the following error is thrown:

TypeError: Cannot read properties of undefined (reading 'tileWidth')

The issue is caused by var sid = tiles[index][2]; in PutTileAt.js. This tileset id is wrong if not all tilesets have been added to the layer. In my case Phaser assumes the sid is "2" when it should actually be "0".

So if I change my code accordingly, the error disappears:

map.createLayer(
      "MyNewLayer",
      [tileset1, tileset2, tileset3],
      0,
      0
    );

It is probably not the intention to require that all tilesets have to be added to all layers, so I think this is a bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions