当插入到CCDictionary中时,将标签添加到扩展CCNode的Cocos2d-x将消失

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

本文关键字:CCNode 扩展 Cocos2d-x 消失 添加 标签 CCDictionary 中时 插入      更新时间:2023-10-16

我尝试设置标记,它成功了,但当我将CCnode插入CCDictionary时并尝试获取CCNode并检查标签,其为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 ???

您可以尝试使用std::map<std::string, Gem *>而不是CCDictionary