mirror of
https://github.com/photonstorm/phaser
synced 2025-01-10 20:28:56 +00:00
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
/**
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
*/
|
|
|
|
/**
|
|
* Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the
|
|
* layer's position, scale and scroll.
|
|
*
|
|
* @function Phaser.Tilemaps.Components.TileToWorldY
|
|
* @since 3.0.0
|
|
*
|
|
* @param {integer} tileY - [description]
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - [description]
|
|
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
|
*
|
|
* @return {number}
|
|
*/
|
|
var TileToWorldY = 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;
|
|
}
|
|
|
|
return layerWorldY + tileY * tileHeight;
|
|
};
|
|
|
|
module.exports = TileToWorldY;
|