JSFiddle - React, Tailwind, and code Playground
JavaScript
// Faking example_map.json load which you would create using tiled
//
// You would access this in your game with e.g.
//
// this.load.json("mapJson", "../assets/maps/example_map.json");
// ...
// var exampleMap = self.cache.getJSON("mapJson");
var exampleJson = JSON.parse('{"height":3,"layers":[{"data":[0,0,0,0,0,0,0,0,0],"height":3,"name":"Example_layer","opacity":1,"type":"tilelayer","visible":true,"width":3,"x":0,"y":0}],"orientation":"orthogonal","properties":{"collides":"19,23,18,28"},"tileheight":80,"tilesets":[],"tilewidth":80,"version":1,"width":3}');
/**
*
*
*/
var parseMap = function(mapJson) {
// handle your map properties, now only collides
// fetching the block tiles
var _collides = mapJson.properties.collides.split(",");
// from string to number
for (var i = 0; i < _collides.length; i++) {
_collides[i] = parseInt(_collides[i], 10);
}
// do what ever you want with your array
// will print [19, 23, 18, 28] to console
console.log(_collides);
};
// demo
parseMap(exampleJson);