2017-11-17 02:36:45 +00:00
|
|
|
var SnapFloor = require('../../../math/snap/SnapFloor');
|
|
|
|
|
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-17 02:36:45 +00:00
|
|
|
var tilemapLayer = layer.tilemapLayer;
|
|
|
|
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,
|
|
|
|
// factoring in the camera's horizontal scroll
|
|
|
|
worldY = worldY + (camera.scrollY * tilemapLayer.scrollFactorY) - tilemapLayer.y;
|
|
|
|
}
|
|
|
|
|
2017-11-25 13:08:06 +00:00
|
|
|
return snapToFloor
|
|
|
|
? SnapFloor(worldY, layer.tileHeight) / layer.tileHeight
|
|
|
|
: worldY / layer.tileHeight;
|
2017-11-17 02:36:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = WorldToTileY;
|