Skip to content

WorldToTileX not working for Hex Tilesets (TileY and TileXY works) #5608

Closed
@stonerich

Description

@stonerich

Version

  • Phaser Version: 3.53.1
  • Operating system: MacOS MigSur
  • Browser:

Description

Tilemaplayer.worldToTileX gives undefined in the code below. Expected behavior is to get the X pos

However, both ..ToTileXY and ... ToTileY works

It seems that the GetWorldToTileXFunction (Phaser.Tilemaps.Components.GetWorldToTileXFunction) is not updated in the same way as GetWorldToTileYFunction is.

var GetWorldToTileXFunction = function (orientation)
{
    if (orientation === CONST.ORTHOGONAL)
    {
        return WorldToTileX;
    }
    else
    {
        return NOOP;
    }
};
var GetWorldToTileYFunction = function (orientation)
{
    if (orientation === CONST.ORTHOGONAL)
    {
        return WorldToTileY;
    }
    else if (orientation === CONST.HEXAGONAL)
    {
        return HexagonalWorldToTileY;
    }
    else if (orientation === CONST.STAGGERED)
    {
        return StaggeredWorldToTileY;
    }
    else
    {
        return NOOP;
    }
};

Example Test Code

this.map = this.make.tilemap({key: 'hexmap'});
this.tiles = this.map.addTilesetImage('Hexagons')
this.layer = this.map.createLayer('Map', this.tiles, 20, 30);

this.layer.setInteractive();
this.layer.on('pointerup', (pointer) => {
    console.log("Pointer Up " , pointer, pointer.downX);        
    let tileX = this.layer.worldToTileX(pointer.downX, true);
    let tileXY = this.layer.worldToTileXY(pointer.downX, pointer.downY, true);
    let tileY = this.layer.worldToTileY(pointer.downY, true);
    console.log("Tile", tileXY, tileX, tileY);

});

Additional Information

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