Search code examples
c++cocos2d-x

Cocos2d-x adding tag to extended CCNode disappear when insert in to CCDictionary


I try to set tag and it does successfully but when i insert the CCnode in to CCDictionary and try to get the CCNode and checking the tag , its 0.

int tagNum = 242;   
    //Gem is class Gem :public CCNode , public CCTargetedTouchDelegate 
    Gem *thisGem = new Gem();
    thisGem->retain();
    thisGem->setTag(tagNum);
    thisGem->initWithGame(this,zorder);
    int t1 = thisGem->getTag();
    // t1 = 242
    //set in container
    std::string gemID = thisGem->getGemId();
    gemsDictionary->setObject(thisGem,gemID); //gemsDictionary init in the contracture 
    Gem *nextGemTest = (Gem *)gemsDictionary->objectForKey(gemID); 
    int t2 = nextGemTest->getTag();
    // t2 is 0 ???

Solution

  • You can try to use std::map<std::string, Gem *> instead of CCDictionary