@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?
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.
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).