Calculating x, y position of object in CCTMXMapInfo has bug for isometric

I think there is a bug to calculating x, y position of object in CCTMXMapInfo, CCTMXXMLParser.cpp.

Line 513
x position is just stored with position offset.

int x = atoi(value) + (int)objectGroup->getPositionOffset().x;@

Line 525
y position is calculating as

int y = atoi(value) + (int)objectGroup->getPositionOffset().y;
y = (int)(m_tMapSize.height * m_tTileSize.height) - y - atoi(valueForKey("height", attributeDict));

It may correct for Orthogonal map
but it is not correct for Isometric map and may also Hexagonal.

For instance,
let’s say map is 30x30, tilesize is 200x100.

the location for the coord (0, 0) object in Isometric map should be the center of the very top.

It’s position is stored as following in tmx file

and in source code, following is calcuation
x = 0;
but which should be the center of position which shoud be the 2900 ~ 3100.

y = (int)(m_tMapSize.height * m_tTileSize.height) - y - atoi(valueForKey(“height”, attributeDict));
y = 30 * 100 - 0 - 100
= 2900

What do you think?

You’re right, I’ve been struggling with this problem for two days thinking it was my fault :frowning: , any idea to solve it quickly? :;qst

This is technically not a bug, but rather a literal parsing of Tiled’s export format .tmx for objects. See the format doc and look at the note by x,y.

I think you are correct, however, that it makes sense to have TMXMapInfo parse with cocos2d-x’s lower left origin in mind. I can’t think of a reason that someone would need to get the original top-left origin values?

I think the final solution or fix would be to improve the tile map classes in the engine to abstract to a higher level, while working to support low-level customization or hooks where it makes sense. Possibly by keeping the current classes as they exist, but wrapping them in a more friendly API if you want to not have to worry about parsing out the object’s Value properties directly.

Regardless the main issue is documentation of course.