Skip to content

Commit

Permalink
Fixed #6996. Updated calculation for widthInPixels and heightInPixels…
Browse files Browse the repository at this point in the history
… in MapData. Thanks @ptantiku
  • Loading branch information
zekeatchan committed Jan 6, 2025
1 parent bd67680 commit ab88e71
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/tilemaps/parsers/tiled/ParseJSONTiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions src/tilemaps/parsers/tiled/ParseTileLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ var ParseTileLayers = function (json, insertNull)
var gidInfo;
var tile;
var blankTile;
var triangleHeight;
var triangleWidth;

var output = [];
var x = 0;
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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 = [];

Expand Down

0 comments on commit ab88e71

Please sign in to comment.