Skip to content

convertTilemapLayer for isometric tilemaps not setting bodies properly #5764

@mayacoda

Description

@mayacoda

Version

  • Phaser Version: 3.55.2
  • Operating system: macOS
  • Browser:

Description

I'm having an issue with setting up collisions with a staggered isometric tilemap created in Tiled. I ran across this discussion outlining the same issue, and I can confirm it's still a problem in 3.55.2. Basically, convertTilemapLayer does not set the collision bodies for tiles correctly on isometric maps, neither the default rectangle nor the shape specified in the collision layer.

As suggested in the thread, the issue comes from getBounds() on the Tile class. Specifically, this.getLeft() always returns undefined for any of the tiles.

    getBounds: function (camera, output)
    {
        if (output === undefined) { output = new Rectangle(); }

        output.x = this.getLeft();
        output.y = this.getTop();
        output.width = this.getRight() - output.x;
        output.height = this.getBottom() - output.y;

        return output;
    }

Example Test Code

    const map = this.make.tilemap({ key: 'map' })
    const tileset = map.addTilesetImage('tileset', 'tiles')
    const ground = map.createLayer('Floor', tileset)

    // property "collides" is set on certain tiles within Tiled
    ground.setCollisionByProperty({ collides: true })

    this.matter.world.convertTilemapLayer(ground)

Additional Information

I'm happy to give solving this a shot myself if you could provide some guidance. 🙂

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