From e6d99083d92ea9ec1ab65c8c18f30104d194afee Mon Sep 17 00:00:00 2001 From: Zeke Chan Date: Mon, 6 Jan 2025 16:50:35 +0800 Subject: [PATCH] Fixed #6992. Updated calculation for widthInPixels and heightInPixels in MapData. Thanks @ptantiku --- src/tilemaps/parsers/tiled/ParseJSONTiled.js | 13 +++++++++ src/tilemaps/parsers/tiled/ParseTileLayers.js | 28 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/tilemaps/parsers/tiled/ParseJSONTiled.js b/src/tilemaps/parsers/tiled/ParseJSONTiled.js index ce4a575665..a9342715b2 100644 --- a/src/tilemaps/parsers/tiled/ParseJSONTiled.js +++ b/src/tilemaps/parsers/tiled/ParseJSONTiled.js @@ -57,6 +57,19 @@ var ParseJSONTiled = function (name, source, insertNull) mapData.hexSideLength = json.hexsidelength; mapData.staggerAxis = json.staggeraxis; mapData.staggerIndex = json.staggerindex; + + if (mapData.staggerAxis === 'y') + { + var triangleHeight = (mapData.tileHeight - mapData.hexSideLength) / 2; + mapData.widthInPixels = mapData.tileWidth * (mapData.width + 0.5); + mapData.heightInPixels = mapData.height * (mapData.hexSideLength + triangleHeight) + triangleHeight; + } + else + { + var triangleWidth = (mapData.tileWidth - mapData.hexSideLength) / 2; + mapData.widthInPixels = mapData.width * (mapData.hexSideLength + triangleWidth) + triangleWidth; + mapData.heightInPixels = mapData.tileHeight * (mapData.height + 0.5); + } } mapData.layers = ParseTileLayers(json, insertNull); diff --git a/src/tilemaps/parsers/tiled/ParseTileLayers.js b/src/tilemaps/parsers/tiled/ParseTileLayers.js index 0b01c246a5..6c3a8d0038 100644 --- a/src/tilemaps/parsers/tiled/ParseTileLayers.js +++ b/src/tilemaps/parsers/tiled/ParseTileLayers.js @@ -111,6 +111,8 @@ var ParseTileLayers = function (json, insertNull) var gidInfo; var tile; var blankTile; + var triangleHeight; + var triangleWidth; var output = []; var x = 0; @@ -140,6 +142,19 @@ var ParseTileLayers = function (json, insertNull) layerData.hexSideLength = json.hexsidelength; layerData.staggerAxis = json.staggeraxis; layerData.staggerIndex = json.staggerindex; + + if (layerData.staggerAxis === 'y') + { + triangleHeight = (layerData.tileHeight - layerData.hexSideLength) / 2; + layerData.widthInPixels = layerData.tileWidth * (layerData.width + 0.5); + layerData.heightInPixels = layerData.height * (layerData.hexSideLength + triangleHeight) + triangleHeight; + } + else + { + triangleWidth = (layerData.tileWidth - layerData.hexSideLength) / 2; + layerData.widthInPixels = layerData.width * (layerData.hexSideLength + triangleWidth) + triangleWidth; + layerData.heightInPixels = layerData.tileHeight * (layerData.height + 0.5); + } } for (var c = 0; c < curl.height; c++) @@ -221,6 +236,19 @@ var ParseTileLayers = function (json, insertNull) layerData.hexSideLength = json.hexsidelength; layerData.staggerAxis = json.staggeraxis; layerData.staggerIndex = json.staggerindex; + + if (layerData.staggerAxis === 'y') + { + triangleHeight = (layerData.tileHeight - layerData.hexSideLength) / 2; + layerData.widthInPixels = layerData.tileWidth * (layerData.width + 0.5); + layerData.heightInPixels = layerData.height * (layerData.hexSideLength + triangleHeight) + triangleHeight; + } + else + { + triangleWidth = (layerData.tileWidth - layerData.hexSideLength) / 2; + layerData.widthInPixels = layerData.width * (layerData.hexSideLength + triangleWidth) + triangleWidth; + layerData.heightInPixels = layerData.tileHeight * (layerData.height + 0.5); + } } var row = [];