2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2022-02-28 14:29:51 +00:00
|
|
|
* @copyright 2022 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2017-11-27 13:33:30 +00:00
|
|
|
/**
|
2020-10-02 10:16:32 +00:00
|
|
|
* Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the
|
2017-11-30 15:22:54 +00:00
|
|
|
* layer's position, scale and scroll.
|
2017-11-27 13:33:30 +00:00
|
|
|
*
|
2018-02-08 01:08:59 +00:00
|
|
|
* @function Phaser.Tilemaps.Components.TileToWorldY
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileY - The y coordinate, in tiles, not pixels.
|
2020-11-23 10:48:24 +00:00
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to use when calculating the tile index from the world values.
|
2018-02-08 02:02:37 +00:00
|
|
|
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
2020-09-02 10:54:24 +00:00
|
|
|
*
|
2020-10-02 10:16:32 +00:00
|
|
|
* @return {number} The Y location in world coordinates.
|
2017-11-27 13:33:30 +00:00
|
|
|
*/
|
2020-10-02 10:16:32 +00:00
|
|
|
var TileToWorldY = function (tileY, camera, layer)
|
2017-11-26 13:55:44 +00:00
|
|
|
{
|
2017-12-01 19:25:48 +00:00
|
|
|
var tileHeight = layer.baseTileHeight;
|
2017-11-26 13:55:44 +00:00
|
|
|
var tilemapLayer = layer.tilemapLayer;
|
|
|
|
var layerWorldY = 0;
|
|
|
|
|
|
|
|
if (tilemapLayer)
|
|
|
|
{
|
2020-11-23 10:48:24 +00:00
|
|
|
if (!camera) { camera = tilemapLayer.scene.cameras.main; }
|
2020-09-19 08:56:05 +00:00
|
|
|
|
2017-11-30 15:22:54 +00:00
|
|
|
layerWorldY = (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
|
2017-11-26 13:55:44 +00:00
|
|
|
|
|
|
|
tileHeight *= tilemapLayer.scaleY;
|
|
|
|
}
|
|
|
|
|
2020-10-02 10:16:32 +00:00
|
|
|
return layerWorldY + tileY * tileHeight;
|
2017-11-26 13:55:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = TileToWorldY;
|