Search code examples
c++cocos2d-xcocos2d-x-3.0

Cocos2d: error no suitable conversion function from Cocos2d::Valuemap to Cocos2d::CCdictionary existis


I'm following this amazing tutorial about implementing tilemaps in my game http://www.raywenderlich.com/39113/cocos2d-x-tile-map-tutorial-part-1

http://www.raywenderlich.com/40544/cocos2d-x-tile-map-tutorial-part-2

But when i get to this:

CCTMXObjectGroup *objectGroup = _tileMap->objectGroupNamed("Objects");

if(objectGroup == NULL){
    CCLog("tile map has no objects object layer");
    return false;
}

CCDictionary *spawnPoint = objectGroup->objectNamed("SpawnPoint");

int x = ((CCString)*spawnPoint->valueForKey("x")).intValue();
int y = ((CCString)*spawnPoint->valueForKey("y")).intValue();

_player = new CCSprite();
_player->initWithFile("Player.png");
_player->setPosition(ccp(x,y));

this->addChild(_player);
this->setViewPointCenter(_player->getPosition());

I get an error on: CCDictionary *spawnPoint = objectGroup->objectNamed("SpawnPoint");

Stating that there is no function to convert this objectGroup. (error no suitable conversion function from Cocos2d::Valuemap to Cocos2d::CCdictionary existis)

This looks like a problem from the diferents cocos' versions used (The tutorial is v2 and i'm v3).

Does anyone knows how to fix this?


Solution

  • Why don't you use a auto pointer, and access the unordered map returned using the normal C++ syntax. See below for code sample.

    auto spawnPoints = objectGroupd->objectNamed("SpawnPoint");
    int x = spawnPoints.at("x").asInt();
    int y = spawnPoints.at("y").asInt();
    

    This will get you the same values that the raywenderlich tutorial expects you to have.