1
\$\begingroup\$

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");
this->addChild(tileMap);

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 ?

\$\endgroup\$
1
\$\begingroup\$
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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.