phaser/src/tilemaps/components/WorldToTileXY.js

30 lines
1.1 KiB
JavaScript
Raw Normal View History

var WorldToTileX = require('./WorldToTileX');
var WorldToTileY = require('./WorldToTileY');
2018-02-07 17:10:01 +00:00
var Vector2 = require('../../math/Vector2');
2017-11-27 13:33:30 +00:00
/**
* Converts from world XY coordinates (pixels) to tile XY coordinates (tile units), factoring in the
* layer's position, scale and scroll. This will return a new Vector2 object or update the given
* `point` object.
*
* @param {number} worldX - [description]
* @param {number} worldY - [description]
* @param {boolean} [snapToFloor=true] - Whether or not to round the tile coordinate down to the
* nearest integer.
* @param {Vector2} [point] - [description]
* @param {Camera} [camera=main camera] - [description]
* @param {LayerData} layer - [description]
2018-02-07 23:27:01 +00:00
* @return {Vector2} The XY location in tile units.
2017-11-27 13:33:30 +00:00
*/
var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
{
if (point === undefined) { point = new Vector2(0, 0); }
point.x = WorldToTileX(worldX, snapToFloor, camera, layer);
point.y = WorldToTileY(worldY, snapToFloor, camera, layer);
return point;
};
module.exports = WorldToTileXY;