2017-11-25 13:08:06 +00:00
|
|
|
var WorldToTileY = function (worldY, snapToFloor, camera, layer)
|
2017-11-17 02:36:45 +00:00
|
|
|
{
|
2017-11-25 13:08:06 +00:00
|
|
|
if (snapToFloor === undefined) { snapToFloor = true; }
|
|
|
|
|
2017-11-25 23:12:24 +00:00
|
|
|
var tileHeight = layer.tileHeight;
|
2017-11-17 02:36:45 +00:00
|
|
|
var tilemapLayer = layer.tilemapLayer;
|
2017-11-25 23:12:24 +00:00
|
|
|
|
2017-11-17 02:36:45 +00:00
|
|
|
if (tilemapLayer)
|
|
|
|
{
|
|
|
|
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
|
|
|
|
|
|
|
|
// Find the world position relative to the static or dynamic layer's top left origin,
|
2017-11-25 23:12:24 +00:00
|
|
|
// factoring in the camera's vertical scroll
|
2017-11-17 02:36:45 +00:00
|
|
|
worldY = worldY + (camera.scrollY * tilemapLayer.scrollFactorY) - tilemapLayer.y;
|
2017-11-25 23:12:24 +00:00
|
|
|
|
|
|
|
tileHeight *= tilemapLayer.scaleY;
|
2017-11-17 02:36:45 +00:00
|
|
|
}
|
|
|
|
|
2017-11-25 13:08:06 +00:00
|
|
|
return snapToFloor
|
2017-11-25 23:12:24 +00:00
|
|
|
? Math.floor(worldY / tileHeight)
|
|
|
|
: worldY / tileHeight;
|
2017-11-17 02:36:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = WorldToTileY;
|