phaser icon indicating copy to clipboard operation
phaser copied to clipboard

Phaser.Tilemaps.Tilemap.putTileAt() failing

Open kpotschi opened this issue 1 year ago • 0 comments

Version

  • Phaser Version: 3.60.0
  • Operating system: MacOS

Description

The method is failing with Uncaught TypeError: can't access property "tileWidth", set is undefined

originating from @function Phaser.Tilemaps.Components.PutTileAt

In the documentation, as well as the types, the method expects string | number | [Phaser.Tilemaps.TilemapLayer], while in the static method this is based off, Phaser.Tilemaps.LayerData is expected to be passed in.

Tracing the error, you can see that var set = layer.tilemapLayer.tileset[sid]; is trying to be accessed, which does not exist if typeof layer === Phaser.Tilemaps.TilemapLayer.

Using @ts-ignore and passing in Phaser.Tilemaps.TilemapLayer.layer, makes everything run without errors, but fails to essentially put the new tile in it's place.

Example Test Code

const map = scene.make.tilemap({ key: 'test-map' })

const beachTileset = map.addTilesetImage('beach', 'tileset_beach')

const groundLayer = map.createLayer('ground', beachTileset, 0, 0)

// @ts-ignore
map.putTileAt(67, 1, 1, true, groundLayer.layer)

groundLayer.setCollisionByProperty({ collides: true })

scene.matter.world.convertTilemapLayer(groundLayer)

kpotschi avatar May 08 '23 11:05 kpotschi