0
我嘗試設置標籤並且它成功,但是當我將CCnode插入到CCDictionary 並嘗試獲取CCNode並檢查標籤時,它的值爲0。當插入到CCDictionary中時,Cocos2d-x向擴展CCNode添加標籤消失
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 ???
爲什麼呢? CCDictionary有什麼問題,我想了解它爲什麼發生 – user63898
你應該看看CCDictionary的來源,也許它使用自己的porpuses標籤。 – Seagull
你檢查過thisGem-> getGemId()是否改變標籤值嗎?如果您使用xcode進行開發,您可以「觀察」標籤值以進行更改並找到罪魁禍首。 – GizmoThunder