mapeditor / tiled

Flexible level editor
https://www.mapeditor.org/
Other
11.02k stars 1.74k forks source link

Objects coords on isometric maps #290

Open alaa-eddine opened 11 years ago

alaa-eddine commented 11 years ago

there is something wrong with objects coordinate in isometric maps. let's say we have created an isometric map with 92x46 tiles size and 32x32 tiles number.

we draw an object on top of on a tile, let's say at x=23 , y=12 we save the map to tmx format.

the resulting tmx file will save this object as :

<object type="myObject" x="1058" y="552" width="46" height="46">

to get back the isometric coords I need to divide 1058 by 46 and 552 by 46 .... but this doen't make any sens for X ! cause in isometric mode with and height are different !

bjorn commented 11 years ago

None of it makes sense, indeed. And that's because the object coordinates are stored in pixels. This is because of historical reasons (for orthogonal maps, pixels make perfect sense), but it's somewhat confusing for isometric maps.

On isometric maps the x and y axis go diagonally downwards from the origin point. Even though the tile graphics are non-square, they are conceptually square when looking down the x and y axis (at least in the isometric projections supported by Tiled). Ultimately, the choice to store the object position and size by multiplying by the tile width was rather arbitrary, and the result are "virtual pixel coordinates" that go along the x and y axis of the isometric map.

The fix, as far as I can see, would be:

Unfortunately, such changes would mean breaking the backwards compatibility of the map format. Eventually, it might make sense to get rid of this (and possible other) weirdness and do a "TMX 2.0".

alaa-eddine commented 11 years ago

or maybe by adding a "meta-data" only yo objects on isometric maps to preserve retro compatibility and make it possible to store tile coordinate.

my example becomes :

<object type="myObject" x="1058" y="552" width="46" height="46" vx="23" vy="12">

or

<object type="myObject" x="1058" y="552" width="46" height="46">
   <coords x="23" y="12" />
</object>
babelshift commented 11 years ago

I know this issue is old, but I just ran into it. It took me a second to realize that Tiled was actually storing the coordinates in pixel format rather than tile index (like tiles are stored). But since objects can be 0 to many tiles in width and height, I'm not sure how positioning in terms of tile indices would even work.

Another related issue I've had is the width and height of objects in isometric view. When I set my map to isometric with tiles 64 wide by 32 high and place a rectangular object that is exactly 1 tile in width and height, the resulting width and height is 32x32. Why is this? I would expect the width and height to match the tile width and height that it encompasses.

EDIT: I perhaps understand it now. The object width and height is actually the calculation of the rhombus sides. In a 64x32 isometric tiled word, the objects will have sides equal to (1/2) * (sqrt(64^2 + 32^2)), or 32.