Incorrect object positioning on map layers

Hi all

Just wondering how I can correct a problem I’m observing with objects created on an object layer in Tiled. The positioning I’m viewing in Tiled is not reproduced within Corona. The positions are offset by x + 32 and y -32. 

I.e an object I position at 100, 100 in Tiled has the pixel position (object.x and object.y) of 132, 68. 32 is half the tile width of 64.

Is there a setting I need to configure to positioning  elements with a 0,0 anchor for example?

I attach the map and tiles and the code I use to load it is below

map = dusk.buildMap("level\_tilesets/levels.json") map.x = display.contentCenterX - (display.actualContentWidth/2) map.y = display.contentCenterY - (display.actualContentHeight/2) map:scale(1, 1) map.updateView() -- print(pretty.write(object\_layer.visible)) local object\_layer = map.layer["objects"] local tile\_layer = map.layer["level1"] for index, object\_type in ipairs({"wall", "enemy"}) do for object in object\_layer.typeIs(object\_type) do print(object.x .. " " .. object.y .. " " .. object.anchorX .. " " .. object.anchorY) physics.addBody(object, "static") end end

Slightly confused why in the code 

layer/objectlayer.lua, lines 396 to 402 are

-- Tile image elseif o.gid then data.type = "image" data.transfer.\_objType = "image" data.tileData = tileIndex[o.gid] data.transfer.x, data.transfer.y = o.x + mapData.stats.tileWidth \* 0.5, o.y - mapData.stats.tileHeight \* 0.5 data.width, data.height = tileWidth, tileHeight

rather than

-- Tile image elseif o.gid then data.type = "image" data.transfer.\_objType = "image" data.tileData = tileIndex[o.gid] data.transfer.x, data.transfer.y = o.x + o.width \* 0.5, o.y - o.height \* 0.5 data.width, data.height = o.width, o.height

Here the object x,y, widths and heights are based on the object image properties rather than assuming they conform to the tileset which is used in the tiles layer.

Am I missing something?

I’ll post this in githib too

Hm. I think back in the day (read: when Dusk first came out), it didn’t have so much support for object layers, and I’ve never really questioned my initial genius (:P). I’ll provide a fix for this, or, if you want, you can submit a pull request.

  • Caleb

Hi Caleb. I’d be happy to submit a pull request but do you think my code makes sense. It could easily break someone else’s code I fear :(.

Ant 

I don’t think it’ll break any code - it is a bug, after all. If people are relying on buggy behavior to make their game, that’s not so good :D. I think I actually fixed this in one branch of Dusk a while ago but it seems to have rolled back somehow. As long as it works correctly with your edited code, go right ahead.

  • Caleb

Slightly confused why in the code 

layer/objectlayer.lua, lines 396 to 402 are

-- Tile image elseif o.gid then data.type = "image" data.transfer.\_objType = "image" data.tileData = tileIndex[o.gid] data.transfer.x, data.transfer.y = o.x + mapData.stats.tileWidth \* 0.5, o.y - mapData.stats.tileHeight \* 0.5 data.width, data.height = tileWidth, tileHeight

rather than

-- Tile image elseif o.gid then data.type = "image" data.transfer.\_objType = "image" data.tileData = tileIndex[o.gid] data.transfer.x, data.transfer.y = o.x + o.width \* 0.5, o.y - o.height \* 0.5 data.width, data.height = o.width, o.height

Here the object x,y, widths and heights are based on the object image properties rather than assuming they conform to the tileset which is used in the tiles layer.

Am I missing something?

I’ll post this in githib too

Hm. I think back in the day (read: when Dusk first came out), it didn’t have so much support for object layers, and I’ve never really questioned my initial genius (:P). I’ll provide a fix for this, or, if you want, you can submit a pull request.

  • Caleb

Hi Caleb. I’d be happy to submit a pull request but do you think my code makes sense. It could easily break someone else’s code I fear :(.

Ant 

I don’t think it’ll break any code - it is a bug, after all. If people are relying on buggy behavior to make their game, that’s not so good :D. I think I actually fixed this in one branch of Dusk a while ago but it seems to have rolled back somehow. As long as it works correctly with your edited code, go right ahead.

  • Caleb