gpt4 book ai didi

c++ - Cocos2d-x 添加标签到扩展 CCNode 在插入到 CCDictionary 时消失

转载 作者:行者123 更新时间:2023-11-28 07:29:46 24 4
gpt4 key购买 nike

我尝试设置标签并且成功了,但是当我将 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

关于c++ - Cocos2d-x 添加标签到扩展 CCNode 在插入到 CCDictionary 时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17963218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com