Skip to content

Commit 7f733a0

Browse files
committed
[tilemap] parse polygon, ellipses and rectangles
1 parent 3f51721 commit 7f733a0

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

src/tilemap/TilemapParser.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,15 @@ Phaser.TilemapParser = {
346346
var objects = {};
347347
var collision = {};
348348

349+
function slice (obj, fields) {
350+
var sliced = {};
351+
for (var k in fields) {
352+
var key = fields[k];
353+
sliced[key] = obj[key];
354+
}
355+
return sliced;
356+
}
357+
349358
for (var i = 0; i < json.layers.length; i++)
350359
{
351360
if (json.layers[i].type !== 'objectgroup')
@@ -397,9 +406,37 @@ Phaser.TilemapParser = {
397406
}
398407

399408
collision[json.layers[i].name].push(object);
400-
401409
}
410+
// polygon
411+
else if (json.layers[i].objects[v].polygon)
412+
{
413+
var object = slice(json.layers[i].objects[v],
414+
["name", "x", "y", "visible", "properties" ]);
415+
416+
// Parse the polygon into an array
417+
object.polygon = [];
418+
for (var p = 0; p < json.layers[i].objects[v].polygon.length; p++)
419+
{
420+
object.polygon.push([ json.layers[i].objects[v].polygon[p].x, json.layers[i].objects[v].polygon[p].y ]);
421+
}
422+
objects[json.layers[i].name].push(object);
402423

424+
}
425+
// ellipse
426+
else if (json.layers[i].objects[v].ellipse)
427+
{
428+
var object = slice(json.layers[i].objects[v],
429+
["name", "ellipse", "x", "y", "width", "height", "visible", "properties" ]);
430+
objects[json.layers[i].name].push(object);
431+
}
432+
// otherwise it's a rectangle
433+
else
434+
{
435+
var object = slice(json.layers[i].objects[v],
436+
["name", "x", "y", "width", "height", "visible", "properties" ]);
437+
object.rectangle = true;
438+
objects[json.layers[i].name].push(object);
439+
}
403440
}
404441
}
405442

0 commit comments

Comments
 (0)