Okay, this is really interesting. I just updated to the latest version of Tiled yesterday and was surprised to see one of the export options is Lua – it actually spits out Lua code that can be easily used to get all the info about the levels, tiles, etc.
No need anymore to actually read/parse the .tmx file. I’ll paste a small map down below.
Looking at that you can get data for a layer like this:
[lua]
local myMap = require(“tileMapTest”)
local tileData = myMap.layers[1].data
local tilePic = myData.tilesets[1].image
[/lua]
A person *could* continue to pull data from the .tmx file but I’m wondering if that’s a good use of code or not.
[lua]
– this in a file called tileMapTest.lua
return {
version = “1.1”,
luaversion = “5.1”,
orientation = “orthogonal”,
width = 15,
height = 10,
tilewidth = 32,
tileheight = 32,
properties = {},
tilesets = {
{
name = “tileset-platformer”,
firstgid = 1,
tilewidth = 32,
tileheight = 32,
spacing = 0,
margin = 0,
image = “tileset-platformer.png”,
imagewidth = 192,
imageheight = 544,
properties = {},
tiles = {
{
id = 73,
properties = {
[“points”] = “200”
}
}
}
}
},
layers = {
{
type = “tilelayer”,
name = “Tile Layer 1”,
x = 0,
y = 0,
width = 15,
height = 10,
visible = true,
opacity = 1,
properties = {},
encoding = “lua”,
data = {
0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 65, 51, 52, 53, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 65, 0, 0, 58, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 65, 0, 26, 27, 28, 0, 0, 13, 14,
0, 0, 0, 0, 0, 0, 70, 26, 32, 33, 34, 29, 0, 19, 20,
0, 74, 0, 0, 0, 25, 27, 32, 33, 33, 33, 35, 0, 19, 20,
4, 5, 6, 0, 0, 31, 33, 33, 33, 33, 33, 35, 0, 19, 20,
10, 11, 12, 0, 0, 31, 33, 33, 33, 33, 33, 35, 0, 19, 20
}
}
}
}
[/lua]