Two issues when dealing with hexagonal and/or isometric CCTMXTiledMap

My cocos2d-x version is “cocos2d-2.0-rc2-x-2.0.1 @ Jun 29 2012”. I am developing under win32.

In line 95 of “CCTMXLayer.cpp”

this->setContentSize(CC_SIZE_PIXELS_TO_POINTS(CCSizeMake(m_tLayerSize.width * m_tMapTileSize.width, m_tLayerSize.height * m_tMapTileSize.height)));

This is about to set the m_tContentSize of the layer. However, the above calculation applies to orthogonal CCTMXTileMap, but not isometric and hexagonal ones. Here is my modification:

if (m_uLayerOrientation == CCTMXOrientationHex) { float width = (m_tLayerSize.width * 0.75 + 0.25) * m_tMapTileSize.width; float height = m_tLayerSize.width = = 1 ? m_tLayerSize.height * m_tMapTileSize.height : (m_tLayerSize.height + 0.5) * m_tMapTileSize.height; this->setContentSize(CC_SIZE_PIXELS_TO_POINTS(CCSizeMake(width, height))); } else if (m_uLayerOrientation = = CCTMXOrientationIso) { float factor = (m_tLayerSize.width + m_tLayerSize.height) / 2; this->setContentSize(CC_SIZE_PIXELS_TO_POINTS(CCSizeMake(factor * m_tMapTileSize.width, factor * m_tMapTileSize.height))); } else { this->setContentSize(CC_SIZE_PIXELS_TO_POINTS(CCSizeMake(m_tLayerSize.width * m_tMapTileSize.width, m_tLayerSize.height * m_tMapTileSize.height))); }

(There are two C++ equal operators (consecutive equal signs) disappeared in the above codes. They are there where I typed them, but disappeared in the preview area. I don’t know why. Thus I typed [equal][space][equal] instead)

Besides this, there is the second issue regarding isometric and hexagonal maps. For example, I load a 4(width)x3(height) hex map like the one in the attached picture. The boundingBox of the map should be the red rectangle. But after the map is rendered, I find it to be the blue one actually, which is about half the tile height too high.

This question also exists in the case of isometric maps. But I can’t figure out the exact behavior of it.


hex.png (46.2 KB)