How to use CCBReader in cocos2d-x 2.0.1

How to use CCBReader in cocos2d-x 2.0.1
0.0 0


In older version ,
I use to write it with this way
CCNode* bg = CCBReader::nodeGraphFromFileOwner(“bg.ccb”,“”,this);

Now the same thing in new version which is inside the extension folder
CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
CCNode * node = ccbReader->readNodeGraphFromFile(“”, “bg.ccb”, this);

It is not working ? What mistake is happening while initialising ?

Thanks for the help


What’s the error?


I’m trying the same thing, the node returned is null and there is no error message in the traces.
Note that I’m not sure the new CCBReader supports .ccb format, it seems that now it supports .ccbi format.

As far as I’m concerned the problem I have is a bad access because I have a CCMenuItemImage in my ccb node. Maybe there’s a pb with CCMenuItemImage, I’ll try to remove them.


There is a problem with CCMenuItemImage when the target and selector are left empty. I made a small fix in the file CCMenuItemLoader.h :

void CCMenuItemLoader::onHandlePropTypeBlock(CCNode * pNode, CCNode * pParent, CCString * pPropertyName, BlockData * pBlockData, CCBReader * pCCBReader) {
    if(pPropertyName->compare(PROPERTY_BLOCK) == 0) {
        if (pBlockData!=NULL) { //Added this if test to allow CCMenuItemImage without target/selector predefined
            ((CCMenuItem *)pNode)->setTarget(pBlockData->mTarget, pBlockData->mSELMenuHandler);
    } else {
        CCNodeLoader::onHandlePropTypeBlock(pNode, pParent, pPropertyName, pBlockData, pCCBReader);

Here is the code that works for me (cocosBuilder v2.0 RC1 + cocos2d-2.0-rc2-x-2.0.1 @ Jun 29 2012) :

cocos2d::extension::CCNodeLoaderLibrary * ccNodeLoaderLibrary = cocos2d::extension::CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary(); //newDefaultCCNodeLoaderLibrary();
cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
CCNode * node = ccbReader->readNodeGraphFromFile("", "tests.ccbi", this);


I can’t add a CCControlButton in cocosBuilder v2.0 RC1. If I add it, cocos2d-2.0-rc2-x-2.0.1 will be have a Assertion failed when it load a ccbi file.
CCNodeLoader.cpp line:748 Expression:false


lin miao:
Known bug.



@JP Sarda, Thanks for your contribution. I merged your improvement in
Issue #1408 is fixed.