Now that you have your tileset data ready, you need some important map data: You don’t even need to load the image at this point, you only need it when you’re ready to render. Once you have all those properties, you can calculate where in the image any given tile is based on its local tile ID. From the tileset, the data you need for rendering is For the simple case, let’s assume you’re using image-based tilesets.For ease, I highly recommend making sure this list is sorted in ascending order by firstgid, as you’ll be looking up the firstgids of tilesets a lot. This is a map-specific property, so store something like a list of, where tilesetReference refers to a Tileset object that has the tileset’s data. Store the firstgid for each tileset, it’ll be important. For better performance, store tileset data somewhere where you can access it again when you load a different map, as tileset data doesn’t change between maps, only how the tilesets are used changes. Loop over every tileset in the tilesets array and store the important data somewhere accessible. The property names and general structure and most of the possible values are the same between TMX and JSON.īeyond that, where specifically are you getting stuck? The basic approach for just getting data needed to render your tile layers is: The TMX documentation should have most of what you need. You get the same data from both formats (as far as I can tell), but with JSON you get an object you can process when you’d like, whereas with JS you get a function that needs to be executed and which adds the map data to a predetermined list. JSON is easier to read and just as easy to parse. you’re running a system that doesn’t have a JSON library, or using an engine designed around the Tiled JS format), I think you should use JSON instead, and not worry about the JS format at all. Unless you specifically need to use JS (e.g.
0 Comments
Leave a Reply. |