From 1a88ff95bab932b99a7c14ff8b07a7854978a1d9 Mon Sep 17 00:00:00 2001 From: No Date: Fri, 17 Jan 2020 16:15:59 +0100 Subject: [PATCH] updated dynamic layer and tilemap --- src/tilemaps/Tilemap.js | 12 ++++++------ src/tilemaps/components/TileToWorldY.js | 2 -- src/tilemaps/components/WorldToTileX.js | 14 ++------------ src/tilemaps/dynamiclayer/DynamicTilemapLayer.js | 12 ++++++------ 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/tilemaps/Tilemap.js b/src/tilemaps/Tilemap.js index 2660a9d72..1b61fe264 100644 --- a/src/tilemaps/Tilemap.js +++ b/src/tilemaps/Tilemap.js @@ -2345,7 +2345,7 @@ var Tilemap = new Class({ if (layer === null) { return null; } - return TilemapComponents.TileToWorldX(tileX, camera, layer); + return TilemapComponents.TileToWorldX(tileX, camera, layer, this.orientation); }, /** @@ -2370,7 +2370,7 @@ var Tilemap = new Class({ if (layer === null) { return null; } - return TilemapComponents.TileToWorldY(tileX, camera, layer); + return TilemapComponents.TileToWorldY(tileX, camera, layer, this.orientation); }, /** @@ -2397,7 +2397,7 @@ var Tilemap = new Class({ if (layer === null) { return null; } - return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, layer); + return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, layer, this.orientation); }, /** @@ -2468,7 +2468,7 @@ var Tilemap = new Class({ if (layer === null) { return null; } - return TilemapComponents.WorldToTileX(worldX, snapToFloor, camera, layer); + return TilemapComponents.WorldToTileX(worldX, snapToFloor, camera, layer, this.orientation); }, /** @@ -2493,7 +2493,7 @@ var Tilemap = new Class({ if (layer === null) { return null; } - return TilemapComponents.WorldToTileY(worldY, snapToFloor, camera, layer); + return TilemapComponents.WorldToTileY(worldY, snapToFloor, camera, layer,this.orientation); }, /** @@ -2521,7 +2521,7 @@ var Tilemap = new Class({ if (layer === null) { return null; } - return TilemapComponents.WorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer); + return TilemapComponents.WorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer, this.orientation); }, /** diff --git a/src/tilemaps/components/TileToWorldY.js b/src/tilemaps/components/TileToWorldY.js index ac6e4c273..b13f157bd 100644 --- a/src/tilemaps/components/TileToWorldY.js +++ b/src/tilemaps/components/TileToWorldY.js @@ -28,9 +28,7 @@ var TileToWorldY = function (tileY, camera, layer) if (tilemapLayer) { if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; } - layerWorldY = (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY)); - tileHeight *= tilemapLayer.scaleY; } diff --git a/src/tilemaps/components/WorldToTileX.js b/src/tilemaps/components/WorldToTileX.js index b3e23bbeb..54fd9fbc4 100644 --- a/src/tilemaps/components/WorldToTileX.js +++ b/src/tilemaps/components/WorldToTileX.js @@ -27,19 +27,11 @@ var WorldToTileX = function (worldX, snapToFloor, camera, layer, orientation) if (snapToFloor === undefined) { snapToFloor = true; } 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)); @@ -52,10 +44,8 @@ var WorldToTileX = function (worldX, snapToFloor, camera, layer, orientation) ? Math.floor(worldX / tileWidth) : worldX / tileWidth; } else if (orientation === "isometric") { - return snapToFloor - ? Math.floor((worldX/(tileWidth/2) + worldY/(tileHeight/2))/2) - : ((worldX/(tileWidth/2) + worldY/(tileHeight/2))/2); - + console.warn('With isometric map types you have to use the WorldToTileXY function.'); + return null } }; diff --git a/src/tilemaps/dynamiclayer/DynamicTilemapLayer.js b/src/tilemaps/dynamiclayer/DynamicTilemapLayer.js index 7d3d110a7..d447ccc22 100644 --- a/src/tilemaps/dynamiclayer/DynamicTilemapLayer.js +++ b/src/tilemaps/dynamiclayer/DynamicTilemapLayer.js @@ -1178,7 +1178,7 @@ var DynamicTilemapLayer = new Class({ */ tileToWorldX: function (tileX, camera) { - return TilemapComponents.TileToWorldX(tileX, camera, this.layer); + return TilemapComponents.TileToWorldX(tileX, camera, this.layer, this.tilemap.orientation); }, /** @@ -1195,7 +1195,7 @@ var DynamicTilemapLayer = new Class({ */ tileToWorldY: function (tileY, camera) { - return TilemapComponents.TileToWorldY(tileY, camera, this.layer); + return TilemapComponents.TileToWorldY(tileY, camera, this.layer, this.tilemap.orientation); }, /** @@ -1215,7 +1215,7 @@ var DynamicTilemapLayer = new Class({ */ tileToWorldXY: function (tileX, tileY, point, camera) { - return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, this.layer); + return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, this.layer, this.tilemap.orientation); }, /** @@ -1268,7 +1268,7 @@ var DynamicTilemapLayer = new Class({ */ worldToTileX: function (worldX, snapToFloor, camera) { - return TilemapComponents.WorldToTileX(worldX, snapToFloor, camera, this.layer); + return TilemapComponents.WorldToTileX(worldX, snapToFloor, camera, this.layer, this.tilemap.orientation); }, /** @@ -1286,7 +1286,7 @@ var DynamicTilemapLayer = new Class({ */ worldToTileY: function (worldY, snapToFloor, camera) { - return TilemapComponents.WorldToTileY(worldY, snapToFloor, camera, this.layer); + return TilemapComponents.WorldToTileY(worldY, snapToFloor, camera, this.layer, this.tilemap.orientation); }, /** @@ -1307,7 +1307,7 @@ var DynamicTilemapLayer = new Class({ */ worldToTileXY: function (worldX, worldY, snapToFloor, point, camera) { - return TilemapComponents.WorldToTileXY(worldX, worldY, snapToFloor, point, camera, this.layer); + return TilemapComponents.WorldToTileXY(worldX, worldY, snapToFloor, point, camera, this.layer, this.tilemap.orientation); } });