# Incorrect object positioning on map layers

**URL:** <https://forums.solar2d.com/t/incorrect-object-positioning-on-map-layers/336549>\
**Category:** Gymbyl Coding\
**Created:** [November 3, 2015, 11:58am UTC](https://forums.solar2d.com/t/incorrect-object-positioning-on-map-layers/336549 "2015-11-03T11:58:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![antU](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@antU](https://forums.solar2d.com/u/antU)\
**Post date:** [November 3, 2015, 11:58am UTC](https://forums.solar2d.com/t/incorrect-object-positioning-on-map-layers/336549/1 "2015-11-03T11:58:16Z")

</div>

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.&nbsp;

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 &nbsp;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
```

---

<div class="post-metadata">

**Author:** ![antU](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@antU](https://forums.solar2d.com/u/antU)\
**Post date:** [November 3, 2015, 10:34pm UTC](https://forums.solar2d.com/t/incorrect-object-positioning-on-map-layers/336549/2 "2015-11-03T22:34:29Z")

</div>

Slightly confused why in the code&nbsp;

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

---

<div class="post-metadata">

**Author:** ![Caleb\_P](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@Caleb\_P](https://forums.solar2d.com/u/Caleb_P)\
**Post date:** [November 4, 2015, 12:40pm UTC](https://forums.solar2d.com/t/incorrect-object-positioning-on-map-layers/336549/3 "2015-11-04T12:40:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![antU](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@antU](https://forums.solar2d.com/u/antU)\
**Post date:** [November 5, 2015, 5:32pm UTC](https://forums.solar2d.com/t/incorrect-object-positioning-on-map-layers/336549/4 "2015-11-05T17:32:52Z")

</div>

> [@Caleb\\\_P](#):
>
> 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&nbsp;

---

<div class="post-metadata">

**Author:** ![Caleb\_P](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@Caleb\_P](https://forums.solar2d.com/u/Caleb_P)\
**Post date:** [November 6, 2015, 11:44am UTC](https://forums.solar2d.com/t/incorrect-object-positioning-on-map-layers/336549/5 "2015-11-06T11:44:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![antU](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@antU](https://forums.solar2d.com/u/antU)\
**Post date:** [November 3, 2015, 10:34pm UTC](https://forums.solar2d.com/t/incorrect-object-positioning-on-map-layers/336549/6 "2015-11-03T22:34:29Z")

</div>

Slightly confused why in the code&nbsp;

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

---

<div class="post-metadata">

**Author:** ![Caleb\_P](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@Caleb\_P](https://forums.solar2d.com/u/Caleb_P)\
**Post date:** [November 4, 2015, 12:40pm UTC](https://forums.solar2d.com/t/incorrect-object-positioning-on-map-layers/336549/7 "2015-11-04T12:40:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![antU](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@antU](https://forums.solar2d.com/u/antU)\
**Post date:** [November 5, 2015, 5:32pm UTC](https://forums.solar2d.com/t/incorrect-object-positioning-on-map-layers/336549/8 "2015-11-05T17:32:52Z")

</div>

> [@Caleb\\\_P](#):
>
> 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&nbsp;

---

<div class="post-metadata">

**Author:** ![Caleb\_P](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@Caleb\_P](https://forums.solar2d.com/u/Caleb_P)\
**Post date:** [November 6, 2015, 11:44am UTC](https://forums.solar2d.com/t/incorrect-object-positioning-on-map-layers/336549/9 "2015-11-06T11:44:09Z")

</div>

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
