Skip to content

Commit e6d9908

Browse files
committed
Fixed #6992. Updated calculation for widthInPixels and heightInPixels in MapData. Thanks @ptantiku
1 parent ae565cd commit e6d9908

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/tilemaps/parsers/tiled/ParseJSONTiled.js

+13
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ var ParseJSONTiled = function (name, source, insertNull)
5757
mapData.hexSideLength = json.hexsidelength;
5858
mapData.staggerAxis = json.staggeraxis;
5959
mapData.staggerIndex = json.staggerindex;
60+
61+
if (mapData.staggerAxis === 'y')
62+
{
63+
var triangleHeight = (mapData.tileHeight - mapData.hexSideLength) / 2;
64+
mapData.widthInPixels = mapData.tileWidth * (mapData.width + 0.5);
65+
mapData.heightInPixels = mapData.height * (mapData.hexSideLength + triangleHeight) + triangleHeight;
66+
}
67+
else
68+
{
69+
var triangleWidth = (mapData.tileWidth - mapData.hexSideLength) / 2;
70+
mapData.widthInPixels = mapData.width * (mapData.hexSideLength + triangleWidth) + triangleWidth;
71+
mapData.heightInPixels = mapData.tileHeight * (mapData.height + 0.5);
72+
}
6073
}
6174

6275
mapData.layers = ParseTileLayers(json, insertNull);

src/tilemaps/parsers/tiled/ParseTileLayers.js

+28
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ var ParseTileLayers = function (json, insertNull)
111111
var gidInfo;
112112
var tile;
113113
var blankTile;
114+
var triangleHeight;
115+
var triangleWidth;
114116

115117
var output = [];
116118
var x = 0;
@@ -140,6 +142,19 @@ var ParseTileLayers = function (json, insertNull)
140142
layerData.hexSideLength = json.hexsidelength;
141143
layerData.staggerAxis = json.staggeraxis;
142144
layerData.staggerIndex = json.staggerindex;
145+
146+
if (layerData.staggerAxis === 'y')
147+
{
148+
triangleHeight = (layerData.tileHeight - layerData.hexSideLength) / 2;
149+
layerData.widthInPixels = layerData.tileWidth * (layerData.width + 0.5);
150+
layerData.heightInPixels = layerData.height * (layerData.hexSideLength + triangleHeight) + triangleHeight;
151+
}
152+
else
153+
{
154+
triangleWidth = (layerData.tileWidth - layerData.hexSideLength) / 2;
155+
layerData.widthInPixels = layerData.width * (layerData.hexSideLength + triangleWidth) + triangleWidth;
156+
layerData.heightInPixels = layerData.tileHeight * (layerData.height + 0.5);
157+
}
143158
}
144159

145160
for (var c = 0; c < curl.height; c++)
@@ -221,6 +236,19 @@ var ParseTileLayers = function (json, insertNull)
221236
layerData.hexSideLength = json.hexsidelength;
222237
layerData.staggerAxis = json.staggeraxis;
223238
layerData.staggerIndex = json.staggerindex;
239+
240+
if (layerData.staggerAxis === 'y')
241+
{
242+
triangleHeight = (layerData.tileHeight - layerData.hexSideLength) / 2;
243+
layerData.widthInPixels = layerData.tileWidth * (layerData.width + 0.5);
244+
layerData.heightInPixels = layerData.height * (layerData.hexSideLength + triangleHeight) + triangleHeight;
245+
}
246+
else
247+
{
248+
triangleWidth = (layerData.tileWidth - layerData.hexSideLength) / 2;
249+
layerData.widthInPixels = layerData.width * (layerData.hexSideLength + triangleWidth) + triangleWidth;
250+
layerData.heightInPixels = layerData.tileHeight * (layerData.height + 0.5);
251+
}
224252
}
225253
var row = [];
226254

0 commit comments

Comments
 (0)