Forum > Extensions > How to use CCBReader in cocos2d-x 2.0.1

How to use CCBReader in cocos2d-x 2.0.1

By gameprogrammer Posted 2012-07-12 05:31 Comments 6
gameprogrammer
  • Posts: 8

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

dumganhar
  • Posts: 1000

#1 RE: 2012-07-17 07:56

What’s the error?

jptsetung
  • Posts: 32

#2 RE: 2012-07-25 20:36

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.

jptsetung
  • Posts: 32

#3 RE: 2012-07-25 22:30

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);
miaolinvip
  • Posts: 1

#4 RE: 2012-07-26 03:02

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

MildaGenius
  • Posts: 105

#5 RE: 2012-07-27 08:44

walzer
  • Posts: 1735
  • Location: Xiamen, China

#6 RE: 2012-07-29 13:19

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

Less is More. Keep Focus.

Loggin to reply

Copyright © 2010 - 2013 Cocos2d-x.orgClustrmaps