Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differences in rendering collection of images between json and lua format #12

Open
ldurniat opened this issue Dec 5, 2017 · 3 comments

Comments

@ldurniat
Copy link
Contributor

ldurniat commented Dec 5, 2017

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:

return {
  version = "1.1",
  luaversion = "5.1",
  tiledversion = "1.0.3",
  orientation = "orthogonal",
  renderorder = "right-down",
  width = 25,
  height = 40,
  tilewidth = 22,
  tileheight = 22,
  nextobjectid = 1,
  properties = {},
  tilesets = {
    {
      name = "dsfsdfdsf",
      firstgid = 1,
      tilewidth = 22,
      tileheight = 22,
      spacing = 1,
      margin = 33,
      image = "spritelib_gpl/fishdish/fishbaddie_parts.png",
      imagewidth = 640,
      imageheight = 480,
      tileoffset = {
        x = 0,
        y = 0
      },
      grid = {
        orientation = "orthogonal",
        width = 22,
        height = 22
      },
      properties = {},
      terrains = {},
      tilecount = 494,
      tiles = {
        {
          id = 0,
          properties = {
            ["property_1"] = "property_value"
          }
        }
      }
    },
    {
      name = "gdfgdfgdfgdfg",
      firstgid = 495,
      tilewidth = 640,
      tileheight = 480,
      spacing = 0,
      margin = 0,
      tileoffset = {
        x = 0,
        y = 0
      },
      grid = {
        orientation = "orthogonal",
        width = 1,
        height = 1
      },
      properties = {},
      terrains = {},
      tilecount = 3,
      tiles = {
        {
          id = 0,
          image = "spritelib_gpl/fishdish/fishbaddie_parts.png",
          width = 640,
          height = 480
        },
        {
          id = 1,
          image = "spritelib_gpl/fishdish/fishsalmon_parts.png",
          width = 640,
          height = 480
        },
        {
          id = 3,
          image = "spritelib_gpl/fishdish/fishtitle_parts.png",
          width = 640,
          height = 480
        }
      }
    }
  },
  layers = {
    {
      type = "tilelayer",
      name = "Tile Layer 1",
      x = 0,
      y = 0,
      width = 25,
      height = 40,
      visible = true,
      opacity = 1,
      offsetx = 0,
      offsety = 0,
      properties = {},
      encoding = "lua",
      data = {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        495, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 496, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 28, 29, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        133, 134, 0, 0, 0, 0, 0, 0, 54, 55, 56, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 133,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 498, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
      }
    }
  }
}

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

@ldurniat ldurniat changed the title Differences in rendering collection of images between json and lua formats Differences in rendering collection of images between json and lua format Dec 5, 2017
@abigpotostew
Copy link

abigpotostew commented Feb 23, 2018

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.

@superqix
Copy link
Member

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?

@ldurniat
Copy link
Contributor Author

ldurniat commented Aug 17, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants