I want to set my sprite in x coordinate based on an object in TMX map file, this is my code:

tileMap = cocos2d::TMXTiledMap::create("ground.tmx");
ground = tileMap->layerNamed("ground");

TMXObjectGroup *objects = tileMap->objectGroupNamed("objects");
Dictionary *sign = (Dictionary*)objects->objectNamed("sign");

How can i get a value of object in tmx file in Cocos2d x ?

ValueMap sign = objects->getObject("sign");
float x = sign["x"].asFloat();
float y = sign["y"].asFloat();
std::string nameAlias =  sign["name_alias"].asString();

In cocos2d v.3.8, objectNamed("name") will return ValueMap type that contains Value type. You can see in CCValue.h for more details.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .