# What's the algorithm of Object Position in ISO map?

@bjorn I’m wondering what’s the algorithm of Object Position in ISO map?

I’m using the follow algorithm:

``````// objectOffset : the offset value of the object
// tileSize : the tile size of the map
// mapSize.width : the "width" value of map properties
// mapSize.height : the "height" value of map properties
auto posIndexX = objectOffset.x / tileSize.width * 2;
auto posIndexY = objectOffset.y / tileSize.height;

// posX & posY are the position of the image object's Center Bottom point.
auto posX = tileSize.width / 2 * (mapSize.width + posIndexX - posIndexY);
auto posY = tileSize.height / 2 * (mapSize.height * 2 - posIndexX - posIndexY);
``````

The effect is same with Tiled Editor on some TMX files, but it’s different with Tiled Editor on some other TMX files. Could you please show me the correct algorithm?

PS:
My Tiled version is 0.16.1. And I test my algorithm in Cocos Creator 1.3.

I’m sorry that I can’t upload the test resources. Because it’s forbidden for new users.
So I upload them to a server, you can download them here:
https://pan.baidu.com/s/1dFupztZ

The code is over here:

This determines the position of the object. For isometric maps, this is the bottom center of the tile object. If you’re going to calculate the center of the tile graphic from there, you’d need to subtract half the tile height, but taking into account the rotation of the object when needed.

Here “pixel coordinates” is what is displayed in Tiled (and stored in the TMX file). For isometric maps these are projected to “screen coordinates” using the above function, whereas for orthogonal maps the “pixel” and “screen” coordinates are the same.

Thanks for your reply! I think there is an error in the code (Line 499):
`const int originX = map()->height() * tileWidth / 2;`

In my mind, I think it should be:

``````// use map width to calculate the originX.
const int originX = map()->width() * tileWidth / 2;
``````

Please correct me if I’m wrong.

Here’s a picture of an isometric map as implemented in Tiled:

As you can see, the `originX` depends on the height of the map, multiplied by half the tile width (relative to the top-left corner of the darkened area, which is what Tiled considers the origin in screen coordinates).

1 Like

Yep, sorry for my mistake. Thanks for your explanation!