forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTileToWorldX.js
More file actions
28 lines (23 loc) · 803 Bytes
/
Copy pathTileToWorldX.js
File metadata and controls
28 lines (23 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the
* layer's position, scale and scroll.
*
* @param {integer} tileX - [description]
* @param {Camera} [camera=main camera] - [description]
* @param {LayerData} layer - [description]
* @returns {number}
*/
var TileToWorldX = function (tileX, camera, layer)
{
var tileWidth = layer.baseTileWidth;
var tilemapLayer = layer.tilemapLayer;
var layerWorldX = 0;
if (tilemapLayer)
{
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
layerWorldX = tilemapLayer.x + camera.scrollX * (1 - tilemapLayer.scrollFactorX);
tileWidth *= tilemapLayer.scaleX;
}
return layerWorldX + tileX * tileWidth;
};
module.exports = TileToWorldX;