Skip to content

Commit 17df0f7

Browse files
committed
Restored to previous version. phaserjs#4992
1 parent 398bdf4 commit 17df0f7

1 file changed

Lines changed: 5 additions & 117 deletions

File tree

src/tilemaps/components/WorldToTileY.js

Lines changed: 5 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
* @license {@link https://opensource.org/licenses/MIT|MIT License}
55
*/
66

7-
var CONST = require('../../const.js');
8-
97
/**
10-
* Converts from world Y coordinates (pixels) to orthogonal tile Y coordinates (tile units), factoring in the
8+
* Converts from world Y coordinates (pixels) to tile Y coordinates (tile units), factoring in the
119
* layer's position, scale and scroll.
1210
*
13-
* @function Phaser.Tilemaps.Components.OrthoWorldToTileY
14-
* @private
11+
* @function Phaser.Tilemaps.Components.WorldToTileY
1512
* @since 3.0.0
1613
*
1714
* @param {number} worldY - The y coordinate to be converted, in pixels, not tiles.
@@ -21,92 +18,13 @@ var CONST = require('../../const.js');
2118
*
2219
* @return {number} The Y location in tile units.
2320
*/
24-
var OrthoWorldToTileY = function (worldY, snapToFloor, camera, layer)
21+
var WorldToTileY = function (worldY, snapToFloor, camera, layer)
2522
{
26-
2723
if (snapToFloor === undefined) { snapToFloor = true; }
28-
var tileHeight = layer.baseTileHeight;
29-
var tilemapLayer = layer.tilemapLayer;
30-
31-
if (tilemapLayer)
32-
{
33-
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
34-
35-
// Find the world position relative to the static or dynamic layer's top left origin,
36-
// factoring in the camera's vertical scroll
37-
worldY = worldY - (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
38-
39-
tileHeight *= tilemapLayer.scaleY;
40-
41-
}
42-
43-
return snapToFloor
44-
? Math.floor(worldY / tileHeight)
45-
: worldY / tileHeight;
46-
47-
};
4824

49-
/**
50-
* Converts from world Y coordinates (pixels) to staggered tile Y coordinates (tile units), factoring in the
51-
* layer's position, scale and scroll.
52-
*
53-
* @function Phaser.Tilemaps.Components.StagWorldToTileY
54-
* @private
55-
* @since 3.2.2
56-
*
57-
* @param {number} worldY - The y coordinate to be converted, in pixels, not tiles.
58-
* @param {boolean} [snapToFloor=true] - Whether or not to round the tile coordinate down to the nearest integer.
59-
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the tile index from the world values.
60-
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
61-
*
62-
* @return {number} The Y location in tile units.
63-
*/
64-
var StagWorldToTileY = function (worldY, snapToFloor, camera, layer)
65-
{
66-
67-
if (snapToFloor === undefined) { snapToFloor = true; }
6825
var tileHeight = layer.baseTileHeight;
6926
var tilemapLayer = layer.tilemapLayer;
70-
71-
if (tilemapLayer)
72-
{
73-
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
7427

75-
// Find the world position relative to the static or dynamic layer's top left origin,
76-
// factoring in the camera's vertical scroll
77-
worldY = worldY - (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
78-
79-
tileHeight *= tilemapLayer.scaleY;
80-
81-
}
82-
83-
return snapToFloor
84-
? Math.floor(worldY / (tileHeight / 2))
85-
: worldY / (tileHeight / 2);
86-
};
87-
88-
/**
89-
* Converts from world Y coordinates (pixels) to hexagonal tile Y coordinates (tile units), factoring in the
90-
* layer's position, scale and scroll.
91-
*
92-
* @function Phaser.Tilemaps.Components.HexWorldToTileY
93-
* @private
94-
* @since 3.2.2
95-
*
96-
* @param {number} worldY - The y coordinate to be converted, in pixels, not tiles.
97-
* @param {boolean} [snapToFloor=true] - Whether or not to round the tile coordinate down to the nearest integer.
98-
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the tile index from the world values.
99-
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
100-
*
101-
* @return {number} The Y location in tile units.
102-
*/
103-
var HexWorldToTileY = function (worldY, snapToFloor, camera, layer)
104-
{
105-
106-
if (snapToFloor === undefined) { snapToFloor = true; }
107-
var tileHeight = layer.baseTileHeight;
108-
var tilemapLayer = layer.tilemapLayer;
109-
11028
if (tilemapLayer)
11129
{
11230
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
@@ -116,41 +34,11 @@ var HexWorldToTileY = function (worldY, snapToFloor, camera, layer)
11634
worldY = worldY - (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
11735

11836
tileHeight *= tilemapLayer.scaleY;
119-
12037
}
12138

122-
123-
var sidel = layer.hexSideLength;
124-
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
12539
return snapToFloor
126-
? Math.floor(worldY / rowHeight)
127-
: worldY / rowHeight;
128-
};
129-
130-
var nullFunc = function ()
131-
{
132-
console.warn('With the current map type you have to use the WorldToTileXY function.');
133-
return null;
134-
};
135-
136-
var WorldToTileY = function (orientation)
137-
{
138-
switch (orientation)
139-
{
140-
case CONST.ORTHOGONAL:
141-
return OrthoWorldToTileY;
142-
143-
case CONST.HEXAGONAL:
144-
return HexWorldToTileY;
145-
146-
case CONST.STAGGERED:
147-
return StagWorldToTileY;
148-
149-
default:
150-
return nullFunc;
151-
152-
}
153-
40+
? Math.floor(worldY / tileHeight)
41+
: worldY / tileHeight;
15442
};
15543

15644
module.exports = WorldToTileY;

0 commit comments

Comments
 (0)