game Programmer How to use CCBReader in cocos2d-x 2.0.1
Posts 8
Added by game Programmer 10 months ago

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

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

James Chen RE: How to use CCBReader in cocos2d-x 2.0.1
Posts 637
Added by James Chen 10 months ago

What's the error?

JP Sarda RE: How to use CCBReader in cocos2d-x 2.0.1
Posts 32
Added by JP Sarda 10 months ago

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.

JP Sarda RE: How to use CCBReader in cocos2d-x 2.0.1
Posts 32
Added by JP Sarda 10 months ago

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);
this->addChild(node);
lin miao RE: How to use CCBReader in cocos2d-x 2.0.1
Posts 1
Added by lin miao 10 months ago

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

Milda Genius RE: How to use CCBReader in cocos2d-x 2.0.1
Posts 105
Added by Milda Genius 10 months ago
Zhe Wang RE: How to use CCBReader in cocos2d-x 2.0.1
Posts 1642
Location Amoy, China
Added by Zhe Wang 10 months ago

@JP Sarda, Thanks for your contribution. I merged your improvement in http://github.com/cocos2d/cocos2d-x/pull/1138
Issue #1408 is fixed.

Enjoy Coding, Enjoy Life.


(1-6/6)