Skip to content

Commit 6049701

Browse files
committed
Restored previous function
1 parent df320ba commit 6049701

1 file changed

Lines changed: 6 additions & 179 deletions

File tree

src/tilemaps/components/TileToWorldXY.js

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

7-
var CONST = require('../../const.js');
7+
var TileToWorldX = require('./TileToWorldX');
8+
var TileToWorldY = require('./TileToWorldY');
89
var Vector2 = require('../../math/Vector2');
910

1011
/**
1112
* Converts from tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the
1213
* layer's position, scale and scroll. This will return a new Vector2 object or update the given
1314
* `point` object.
1415
*
15-
* @function Phaser.Tilemaps.Components.OrthoTileToWorldXY
16-
* @private
16+
* @function Phaser.Tilemaps.Components.TileToWorldXY
1717
* @since 3.0.0
1818
*
1919
* @param {integer} tileX - The x coordinate, in tiles, not pixels.
@@ -23,188 +23,15 @@ var Vector2 = require('../../math/Vector2');
2323
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
2424
*
2525
* @return {Phaser.Math.Vector2} The XY location in world coordinates.
26-
*
2726
*/
28-
var OrthoTileToWorldXY = function (tileX, tileY, point, camera, layer)
27+
var TileToWorldXY = function (tileX, tileY, point, camera, layer)
2928
{
3029
if (point === undefined) { point = new Vector2(0, 0); }
31-
32-
var tileHeight = layer.baseTileHeight;
33-
var tileWidth = layer.baseTileWidth;
34-
var tilemapLayer = layer.tilemapLayer;
35-
var layerWorldX = 0;
36-
var layerWorldY = 0;
3730

38-
if (tilemapLayer)
39-
{
40-
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
31+
point.x = TileToWorldX(tileX, camera, layer);
32+
point.y = TileToWorldY(tileY, camera, layer);
4133

42-
layerWorldX = tilemapLayer.x + camera.scrollX * (1 - tilemapLayer.scrollFactorX);
43-
44-
tileWidth *= tilemapLayer.scaleX;
45-
46-
layerWorldY = (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
47-
48-
tileHeight *= tilemapLayer.scaleY;
49-
}
50-
51-
point.x = layerWorldX + tileX * tileWidth;
52-
point.y = layerWorldY + tileY * tileHeight;
53-
54-
55-
56-
return point;
57-
};
58-
59-
/**
60-
* Converts from isometric tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the
61-
* layer's position, scale and scroll. This will return a new Vector2 object or update the given
62-
* `point` object.
63-
*
64-
* @function Phaser.Tilemaps.Components.IsoTileToWorldXY
65-
* @private
66-
* @since 3.2.2
67-
*
68-
* @param {integer} tileX - The x coordinate, in tiles, not pixels.
69-
* @param {integer} tileY - The y coordinate, in tiles, not pixels.
70-
* @param {Phaser.Math.Vector2} [point] - A Vector2 to store the coordinates in. If not given a new Vector2 is created.
71-
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the tile index from the world values.
72-
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
73-
*
74-
* @return {Phaser.Math.Vector2} The XY location in world coordinates.
75-
*/
76-
var IsoTileToWorldXY = function (tileX, tileY, point, camera, layer)
77-
{
78-
var tileWidth = layer.baseTileWidth;
79-
var tileHeight = layer.baseTileHeight;
80-
var tilemapLayer = layer.tilemapLayer;
81-
82-
if (point === undefined) { point = new Vector2(0, 0); }
83-
84-
var layerWorldX = 0;
85-
var layerWorldY = 0;
86-
87-
if (tilemapLayer)
88-
{
89-
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
90-
layerWorldX = tilemapLayer.x + camera.scrollX * (1 - tilemapLayer.scrollFactorX);
91-
tileWidth *= tilemapLayer.scaleX;
92-
layerWorldY = (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
93-
tileHeight *= tilemapLayer.scaleY;
94-
}
95-
96-
97-
point.x = layerWorldX + (tileX - tileY) * (tileWidth / 2);
98-
point.y = layerWorldY + (tileX + tileY) * (tileHeight / 2);
99-
100-
101-
return point;
102-
};
103-
104-
/**
105-
* Converts from staggered tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the
106-
* layer's position, scale and scroll. This will return a new Vector2 object or update the given
107-
* `point` object.
108-
*
109-
* @function Phaser.Tilemaps.Components.StagTileToWorldXY
110-
* @private
111-
* @since 3.2.2
112-
*
113-
* @param {integer} tileX - The x coordinate, in tiles, not pixels.
114-
* @param {integer} tileY - The y coordinate, in tiles, not pixels.
115-
* @param {Phaser.Math.Vector2} [point] - A Vector2 to store the coordinates in. If not given a new Vector2 is created.
116-
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the tile index from the world values.
117-
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
118-
*
119-
* @return {Phaser.Math.Vector2} The XY location in world coordinates.
120-
*/
121-
var StagTileToWorldXY = function (tileX, tileY, point, camera, layer)
122-
{
123-
var tileWidth = layer.baseTileWidth;
124-
var tileHeight = layer.baseTileHeight;
125-
var tilemapLayer = layer.tilemapLayer;
126-
127-
if (point === undefined) { point = new Vector2(0, 0); }
128-
129-
var layerWorldX = 0;
130-
var layerWorldY = 0;
131-
132-
if (tilemapLayer)
133-
{
134-
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
135-
layerWorldX = tilemapLayer.x + camera.scrollX * (1 - tilemapLayer.scrollFactorX);
136-
tileWidth *= tilemapLayer.scaleX;
137-
layerWorldY = (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
138-
tileHeight *= tilemapLayer.scaleY;
139-
}
140-
141-
142-
point.x = layerWorldX + tileX * tileWidth + tileY % 2 * (tileWidth / 2);
143-
point.y = layerWorldY + tileY * (tileHeight / 2);
144-
14534
return point;
14635
};
14736

148-
/**
149-
* Converts from hexagonal tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the
150-
* layer's position, scale and scroll. This will return a new Vector2 object or update the given
151-
* `point` object.
152-
*
153-
* @function Phaser.Tilemaps.Components.HexTileToWorldXY
154-
* @private
155-
* @since 3.2.2
156-
*
157-
* @param {integer} tileX - The x coordinate, in tiles, not pixels.
158-
* @param {integer} tileY - The y coordinate, in tiles, not pixels.
159-
* @param {Phaser.Math.Vector2} [point] - A Vector2 to store the coordinates in. If not given a new Vector2 is created.
160-
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the tile index from the world values.
161-
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
162-
*
163-
* @return {Phaser.Math.Vector2} The XY location in world coordinates.
164-
*/
165-
var HexTileToWorldXY = function (tileX, tileY, point, camera, layer)
166-
{
167-
var tileWidth = layer.baseTileWidth;
168-
var tileHeight = layer.baseTileHeight;
169-
var tilemapLayer = layer.tilemapLayer;
170-
171-
if (point === undefined) { point = new Vector2(0, 0); }
172-
var layerWorldX = 0;
173-
var layerWorldY = 0;
174-
175-
if (tilemapLayer)
176-
{
177-
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
178-
layerWorldX = tilemapLayer.x + camera.scrollX * (1 - tilemapLayer.scrollFactorX);
179-
tileWidth *= tilemapLayer.scaleX;
180-
layerWorldY = (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
181-
tileHeight *= tilemapLayer.scaleY;
182-
}
183-
184-
var sidel = layer.hexSideLength;
185-
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
186-
187-
// similar to staggered, because Tiled uses the oddr representation.
188-
point.x = layerWorldX + tileX * tileWidth + tileY % 2 * (tileWidth / 2);
189-
point.y = layerWorldY + tileY * rowHeight;
190-
191-
return point;
192-
};
193-
194-
var TileToWorldXY = function (orientation)
195-
{
196-
switch (orientation)
197-
{
198-
case CONST.STAGGERED:
199-
return StagTileToWorldXY;
200-
case CONST.ISOMETRIC:
201-
return IsoTileToWorldXY;
202-
case CONST.HEXAGONAL:
203-
return HexTileToWorldXY;
204-
default:
205-
return OrthoTileToWorldXY;
206-
}
207-
208-
};
209-
21037
module.exports = TileToWorldXY;

0 commit comments

Comments
 (0)