CCSpriteBatchNode::removeChild & removeAllChildrenWithCleanup

CCSpriteBatchNode::removeChild & removeAllChildrenWithCleanup
0.0 0


I got a problem with CCSpriteBatchNode::removeAllChildrenWithCleanup…
This method seems not set its children’s child sprites m_bUsesBatchNode from true to false.
But if I use removeChild, the child in child node m_bUsesBatchNode is set to false.

for example:

CCSpriteBatchNode batchNode = CCSpriteBatchNode::nodeWithZZZ…
spriteA = CCSprite::initWithXXX…
CCSprite *spriteB = CCSprite::initWithYYY…

batchNode~~>addChild(spriteA); // after addChild, both spriteA and spriteB’s m_bUseBatchNode is true

If I use batchNode~~>removeAllChildrenWithCleanup to remove all children in batch node, spriteB~~>m_bUsesBatchNode still true.
If I use batchNode~~>removeChild, spriteB~~>m_bUsesBatchNode is false.


I may be a bug, I will check it.
Thank you.


I’m sorry I can’t reproduce the problem you described.
My test code like this (the file grossini_dance_atlas.png can be found in tests resource):

    CCSpriteBatchNode* BatchNode = CCSpriteBatchNode::batchNodeWithFile("grossini_dance_atlas.png", 50);
    addChild(BatchNode, 0, 10000);
    CCSprite* sprite1 = CCSprite::spriteWithTexture(BatchNode->getTexture(), CCRectMake(0,0,85,121));
    BatchNode->addChild(sprite1, 0, 1234);

    // log the value of m_bUsesBatchNode
    CCLog("isUsesBatchNode : %d", sprite1->isUsesBatchNode());

    // Switch this bool value to see different between removeAllChildrenWithCleanup() & removeChild()
    bool bRemoveAll = 0;
    if (bRemoveAll)
        BatchNode->removeChild(sprite1, true);

    // log the value of m_bUsesBatchNode after sprite removed
    CCLog("remove method : %s, sprite isUsesBatchNode : %d",
          bRemoveAll ? "removeAllChildrenWithCleanup" : "removeChild",

And the test result is:

// when the value of bRemoveAll is 0, the log :
isUsesBatchNode : 1
remove method : removeChild, sprite isUsesBatchNode : 0

// when the value of bRemoveAll is 1, the log :
isUsesBatchNode : 1
remove method : removeAllChildrenWithCleanup, sprite isUsesBatchNode : 0


I have asked this problem on cocos2d forum and they think that this is a bug.
The two method should be have the same behavior.

Your test code should have another CCSprite sprite2, and add it as child of sprite1.
Then add sprite1 as batchNode’s child.

The result you see should be both sprite1 and sprite2’s m_bUsesBatchNode set from true to false if you use removeChild(sprite1)
But if you use removeAllChildrenWithCleanup, sprite1’s m_bUseBatchNode will be set from true to false but sprite2’s m_bUsesBatchNode is still true.

You can check here:


Sorry for my careless! Issue #644 created for this bug!