File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * @author Richard Davey <rich@photonstorm.com>
3+ * @copyright 2020 Photon Storm Ltd.
4+ * @license {@link https://opensource.org/licenses/MIT|MIT License }
5+ */
6+
7+ /**
8+ * Converts from hexagonal tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the
9+ * layer's position, scale and scroll.
10+ *
11+ * @function Phaser.Tilemaps.Components.HexagonalTileToWorldY
12+ * @since 3.50.0
13+ *
14+ * @param {integer } tileY - The y coordinate, in tiles, not pixels.
15+ * @param {Phaser.Cameras.Scene2D.Camera } [camera=main camera] - The Camera to use when calculating the tile index from the world values.
16+ * @param {Phaser.Tilemaps.LayerData } layer - The Tilemap Layer to act upon.
17+ *
18+ * @return {number } The Y location in world coordinates.
19+ */
20+ var HexagonalTileToWorldY = function ( tileY , camera , layer )
21+ {
22+ var tileHeight = layer . baseTileHeight ;
23+ var tilemapLayer = layer . tilemapLayer ;
24+ var layerWorldY = 0 ;
25+
26+ if ( tilemapLayer )
27+ {
28+ if ( camera === undefined ) { camera = tilemapLayer . scene . cameras . main ; }
29+
30+ layerWorldY = ( tilemapLayer . y + camera . scrollY * ( 1 - tilemapLayer . scrollFactorY ) ) ;
31+
32+ tileHeight *= tilemapLayer . scaleY ;
33+ }
34+
35+ var len = tilemapLayer . tilemap . hexSideLength ;
36+
37+ var rowHeight = ( ( tileHeight - len ) / 2 + len ) ;
38+
39+ return layerWorldY + tileY * rowHeight ;
40+ } ;
41+
42+ module . exports = HexagonalTileToWorldY ;
You can’t perform that action at this time.
0 commit comments