simple question but not sure how to do it
i have 10 CCNodes added as child to the CCLayer
no i want to delete only specific ones .
how can i do it ? do i need to give each CCNode unique tag id
and then delete it by tag ?
or other way ?
If you can get the object itself, then you can use obj -> removeFromParentAndCleanup(true)
.
If not, you must give them a tag, then remove by tag.
Thanks for the replay , i did it but still i can i see the CCNode on the parent .
my final goul is to remove it from the CCLayer
this is my remove function
it takes CCArray with CCNodes and try’s to remove it
void GameLayer::removeGemsMatched(CCArray *&sameRowGemArray)
{
CCLOG("%i",sameRowGemArray->count());
CCObject *aGemIt = NULL;
CCARRAY_FOREACH(sameRowGemArray,aGemIt)
{
Gem *aGem = static_cast(aGemIt);
int gemTag = aGem->getTag();
CCNode* parent = aGem->getParent();
if(parent != NULL)
{
this->removeChild(aGem);
aGem->removeFromParentAndCleanup(true);
aGem->release();
}
}
}
and this is where i create the CCNode:
void GameLayer::createGem(int row,int col,int zorder,int tagNum)
{
Gem *thisGem = new Gem(); // Class That extend CCNode and contains CCSprit as member
thisGem->initWithGame(this,zorder);
thisGem->placeInGride();
thisGem->retain();
gemsDictionary.setObject(thisGem,gemID);
}
the CCNode class that adds the CCNode to the CCLayer
bool Gem::initWithGame(GameLayer* game,int zorder) {
setGameLayer(game);
game->addChild(this,zorder);
return true;
}
this is where i place it on the screen
void Gem::placeInGride()
{
CCSpriteBatchNode *spriteBatchNode = (CCSpriteBatchNode*) getGameLayer()->getChildByTag(kSSheet);
int gemSelect =(rand() % totalGemsAvailable) + 1;
char spritename[20];
sprintf(spritename,"gem%i_tranc.png",gemNum);
mySprite = CCSprite::createWithSpriteFrameName(spritename);
spriteBatchNode->addChild(mySprite, 2);
CCSize sSize = mySprite->getContentSize();
setGemPosition(setPositionForGem(getRowNum(),getColNum(),sSize));
}