mirror of
https://github.com/photonstorm/phaser
synced 2024-12-23 03:23:42 +00:00
wordtotileX or Y cannot be called independently either
This commit is contained in:
parent
ddbcf85194
commit
f17aef0abf
3 changed files with 46 additions and 13 deletions
|
@ -15,6 +15,7 @@
|
|||
* @param {integer} tileY - The x coordinate, in tiles, not pixels.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the tile index from the world values.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
* @param {string} orientation - The Tilemap's orientation
|
||||
*
|
||||
* @return {number}
|
||||
*/
|
||||
|
@ -33,7 +34,13 @@ var TileToWorldY = function (tileY, camera, layer)
|
|||
tileHeight *= tilemapLayer.scaleY;
|
||||
}
|
||||
|
||||
return layerWorldY + tileY * tileHeight;
|
||||
if (orientation === "orthogonal") {
|
||||
return layerWorldY + tileY * tileHeight;
|
||||
} else if (orientation === "isometric") {
|
||||
// Not Best Solution ?
|
||||
console.warn('With isometric map types you have to use the TileToWorldXY function.');
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = TileToWorldY;
|
||||
|
|
|
@ -31,8 +31,42 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer,
|
|||
{
|
||||
if (point === undefined) { point = new Vector2(0, 0); }
|
||||
|
||||
point.x = WorldToTileX(worldX, snapToFloor, camera, layer, orientation);
|
||||
point.y = WorldToTileY(worldY, snapToFloor, camera, layer, orientation);
|
||||
if (orientation === "orthogonal") {
|
||||
point.x = WorldToTileX(worldX, snapToFloor, camera, layer, orientation);
|
||||
point.y = WorldToTileY(worldY, snapToFloor, camera, layer, orientation);
|
||||
} else if (orientation == 'isometric') {
|
||||
|
||||
var tileWidth = layer.baseTileWidth;
|
||||
var tileHeight = layer.baseTileHeight;
|
||||
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 vertical scroll
|
||||
worldY = worldY - (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
|
||||
|
||||
tileHeight *= tilemapLayer.scaleY;
|
||||
|
||||
// Find the world position relative to the static or dynamic layer's top left origin,
|
||||
// factoring in the camera's horizontal scroll
|
||||
worldX = worldX - (tilemapLayer.x + camera.scrollX * (1 - tilemapLayer.scrollFactorX));
|
||||
|
||||
tileWidth *= tilemapLayer.scaleX;
|
||||
}
|
||||
|
||||
point.x = snapToFloor
|
||||
? Math.floor((worldX/(tileWidth/2) + worldY/(tileHeight/2))/2)
|
||||
: ((worldX/(tileWidth/2) + worldY/(tileHeight/2))/2);
|
||||
|
||||
point.y = snapToFloor
|
||||
? Math.floor(worldY/(tileHeight/2) - (worldX/(tileWidth/2))/2)
|
||||
: (worldY/(tileHeight/2) - (worldX/(tileWidth/2))/2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return point;
|
||||
};
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
var WorldToTileY = function (worldY, snapToFloor, camera, layer, orientation)
|
||||
{
|
||||
if (snapToFloor === undefined) { snapToFloor = true; }
|
||||
|
||||
var tileWidth = layer.baseTileWidth;
|
||||
var tileHeight = layer.baseTileHeight;
|
||||
var tilemapLayer = layer.tilemapLayer;
|
||||
|
||||
|
@ -38,11 +36,6 @@ var WorldToTileY = function (worldY, snapToFloor, camera, layer, orientation)
|
|||
|
||||
tileHeight *= tilemapLayer.scaleY;
|
||||
|
||||
// Find the world position relative to the static or dynamic layer's top left origin,
|
||||
// factoring in the camera's horizontal scroll
|
||||
worldX = worldX - (tilemapLayer.x + camera.scrollX * (1 - tilemapLayer.scrollFactorX));
|
||||
|
||||
tileWidth *= tilemapLayer.scaleX;
|
||||
}
|
||||
|
||||
if (orientation === "orthogonal") {
|
||||
|
@ -50,9 +43,8 @@ var WorldToTileY = function (worldY, snapToFloor, camera, layer, orientation)
|
|||
? Math.floor(worldY / tileHeight)
|
||||
: worldY / tileHeight;
|
||||
} else if (orientation === "isometric") {
|
||||
return snapToFloor
|
||||
? Math.floor(worldY/(tileHeight/2) - (worldX/(tileWidth/2))/2)
|
||||
: (worldY/(tileHeight/2) - (worldX/(tileWidth/2))/2);
|
||||
console.warn('With isometric map types you have to use the WorldToTileXY function.');
|
||||
return null
|
||||
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue