phaser/src/tilemaps/components/HexagonalTileToWorldY.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Converts from hexagonal tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the
* layer's position, scale and scroll.
*
* @function Phaser.Tilemaps.Components.HexagonalTileToWorldY
* @since 3.50.0
*
* @param {integer} tileY - The y coordinate, in tiles, not pixels.
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the tile index from the world values.
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
*
* @return {number} The Y location in world coordinates.
*/
var HexagonalTileToWorldY = function (tileY, camera, layer)
{
var tileHeight = layer.baseTileHeight;
var tilemapLayer = layer.tilemapLayer;
var layerWorldY = 0;
if (tilemapLayer)
{
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
layerWorldY = (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
tileHeight *= tilemapLayer.scaleY;
}
var len = tilemapLayer.tilemap.hexSideLength;
var rowHeight = ((tileHeight - len) / 2 + len);
return layerWorldY + tileY * rowHeight;
};
module.exports = HexagonalTileToWorldY;