help me about CCTMXTiledMap

help me about CCTMXTiledMap
0.0 0


I made a “map.tmx” with tiled. like something below:

<map version="1.0" orientation="orthogonal" width="15" height="10" tilewidth="32" tileheight="32"> <tileset name="Untitled" firstgid="1" tilewidth="32" tileheight="32" spacing="1" margin="1"> <image source="background.png"/> </tileset> <layer name="Background" width="15" height="10"> <data encoding="base64" compression="gzip"> H4sIAAAAAAAAAGNkYGBgIhEzA7EcEHMCsQgQC5GAuZH0wtiMUDMVoHx0DBPHphedLYPDzTA1gmjuEcYhjk0NPrcRwhpoGJ+cOhImxmxqYmL9QwgDAPcfaFxYAgAA </data> </layer> <objectgroup name="Objects" width="0" height="0"> <object name="SpawnPoint" x="0" y="288" width="32" height="32"/> </objectgroup> </map>

Here is the problem with the code below:

`_tileMap = CCTMXTiledMap::tiledMapWithTMXFile("./map.tmx");

this->addChild(_tileMap, -1);

CCTMXObjectGroup* objects = _tileMap->objectGroupNamed(“Objects”);
CCMutableDictionary<std::string, CCString*>* spawnPoint = objects->objectNamed(“SpawnPoint”);
int x = spawnPoint->objectForKey(“x”)->toInt();
int y = spawnPoint->objectForKey(“y”)->toInt();`

Here “y” is always 0.


Here is my DEBUG info


This result comes from CCTMXXMLParser.cpp, line 427 ~ 441, under else if (elementName == "object")
I think the reason is that y position is corrected by line 436

// Correct y position. (Tiled uses Flipped, cocos2d uses Standard)
y = (int)(pTMXMapInfo->getMapSize().height * pTMXMapInfo->getTileSize().height) - y - atoi(valueForKey("height", attributeDict));

It may be different from the value in map.tmx. You can trace the source here.


I’m sorry.
In “CCTMXXMLParser.cpp” , on line 435:

// Correct y position. (Tiled uses Flipped, cocos2d uses Standard)
y = (int)(pTMXMapInfo~~>getMapSize.height * pTMXMapInfo~~>getTileSize().height) - y - atoi(valueForKey(“height”, attributeDict));

So I need to set the anchor point of the player.


@Walzer Wang, Thank you for your reply!