Open ldurniat opened 6 years ago
I also ran into this. The issue is reproduced by adding images to a tileset, then removing some, then adding more, etc. This leads to non consecutive IDs for the images, and breaks your logic in findLast
function in ponytiled.lua as well as gidLookup
on this line if gid >= firstgid and gid <= lastgid then
which assumes the gid is consecutive starting at 0
(or 1
, not sure) when in fact the gid can start at any value and still be valid.
For now the workaround is to recreate the tileset and only add images, never remove. If any have been removed then recreate the tileset.
Is this just in the LUA format? Not something I use very often, but the JSON allows for removal and re-adding of tiles... I'll check into it. Maybe someone can upload a sample?
Tha JSON format is also affected by this issue.
I re-added last image shield.png
.
Example:
{ "height":20,
"infinite":false,
"layers":[
{
"draworder":"topdown",
"name":"Object Layer 1",
"objects":[
{
"gid":1,
"height":128,
"id":1,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":128,
"x":157.333333333333,
"y":340
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}],
"nextobjectid":2,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.1.5",
"tileheight":32,
"tilesets":[
{
"columns":0,
"firstgid":1,
"grid":
{
"height":1,
"orientation":"orthogonal",
"width":1
},
"margin":0,
"name":"fgdfg",
"spacing":0,
"tilecount":3,
"tileheight":128,
"tiles":
{
"0":
{
"image":"heart.png",
"imageheight":128,
"imagewidth":128
},
"1":
{
"image":"gem.png",
"imageheight":64,
"imagewidth":64
},
"3":
{
"image":"shield.png",
"imageheight":64,
"imagewidth":64
}
},
"tilewidth":128
}],
"tilewidth":32,
"type":"map",
"version":1,
"width":20
}
Images come from https://github.com/coronalabs/Sticker-Knight-Platformer/tree/master/scene/game/img.
Hi,
this problem is mentioned in this thread on Corona forum. I believe I find easy solution. In function gidLookup you only need to line 150:
if tonumber(k) == (gid - firstgid + 0 ) then
replace with
if (v.id or tonumber(k)) == (gid - firstgid + 0 ) then
NOTE:
I found that your solution don't work in every case since tile ids may be not consecutive numbers. Like in example below:
I first added four images to tileset and then removed 3rd image. After that I saw in Corona Simulator only two images. One image was missing. All three images were visible in Tiled Editor.
Have a nice day:) ldurniat