The proper way to load CocosBuilder file

I’m quite new to CocosBuilder and CCBReader. At first, I have to say, it’s a great tools.

I have two questions about reading the ccbi file:

  1. Here is the code I used to load the ccbi file

CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary();
ccNodeLoaderLibrary~~>registerCCNodeLoader);
cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader;
CCNode * node = ccbReader~~>readNodeGraphFromFile(“Level.ccbi”);

My question is if it’s possible don’t call registerCCNodeLoader ?

  1. I’m trying to port the CocosDragon to cocos2dx version. In that project, some ccb files include sub-ccb files. Will this be a problem ?

Thanks.

1.You must call registerCCNodeLoader. In my project, I have an loadNode common function, in this function, I registered all of my custom loaders.
2. I have tried to use sub-ccb file, but I want to use % position or content size of parent ccb file, so it’s not easy to use like this.
The problem I meet is, the sub-ccb is on the proper position in CocosBuilder, but not in my app.

Ivy Shao wrote:

1.You must call registerCCNodeLoader. In my project, I have an loadNode common function, in this function, I registered all of my custom loaders.
2. I have tried to use sub-ccb file, but I want to use % position or content size of parent ccb file, so it’s not easy to use like this.
The problem I meet is, the sub-ccb is on the proper position in CocosBuilder, but not in my app.

Then that means we have to know the name of the CCLayer class which is assigned in CocosBuilder. What if we don’t assign a class in CocosBuilder?

If you don’t assign a class, then the class name is CCLayer, the basic loaders already registered when you create a loader.
So just read the node.

bagus flyer wrote:

Ivy Shao wrote:
> 1.You must call registerCCNodeLoader. In my project, I have an loadNode common function, in this function, I registered all of my custom loaders.
> 2. I have tried to use sub-ccb file, but I want to use % position or content size of parent ccb file, so it’s not easy to use like this.
> The problem I meet is, the sub-ccb is on the proper position in CocosBuilder, but not in my app.
>
Then that means we have to know the name of the CCLayer class which is assigned in CocosBuilder. What if we don’t assign a class in CocosBuilder?

Let me rephrase my question. Let’s say, I have a few scene files like CCB: scene1.ccbi, scene2.ccbi, scene3.ccbi,… etc. And I have corresponding customer classes for the scenes. What I want is to create the scene by loading the corresponding ccbi files. For example, I have a function to generate load the scene:

void loadScene(const std::string& name)
{
CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
ccNodeLoaderLibrary~~>registerCCNodeLoader, xxxxx::loader);
cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader;
// I can easily to add the ccbi extension here
CCScene* pScene = ccbReader~~>createSceneWithNodeGraphFromFile(“name.ccbi”);
CCDirector::sharedDirector()>replaceScene);
ccbReader
>release();
}

The problem is that I have to use the concrete loader name in the method. Any idea to overcome this problem?

void loadScene(const std::string& name)
{
CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();

ccNodeLoaderLibrary~~>registerCCNodeLoader);
ccNodeLoaderLibrary~~>registerCCNodeLoader(Scene2Class, Scene2ClassLoader.loader());
ccNodeLoaderLibrary~~>registerCCNodeLoader);
cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader;
// I can easily to add the ccbi extension here
CCScene* pScene = ccbReader~~>createSceneWithNodeGraphFromFile(“name.ccbi”);
CCDirector::sharedDirector()>replaceScene);
ccbReader
>release();
}

bagus flyer wrote:

Let me rephrase my question. Let’s say, I have a few scene files like CCB: scene1.ccbi, scene2.ccbi, scene3.ccbi,… etc. And I have corresponding customer classes for the scenes. What I want is to create the scene by loading the corresponding ccbi files. For example, I have a function to generate load the scene:
>
void loadScene(const std::string& name)
{
CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
ccNodeLoaderLibrary~~>registerCCNodeLoader, xxxxx::loader);
cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader;
// I can easily to add the ccbi extension here
CCScene* pScene = ccbReader~~>createSceneWithNodeGraphFromFile(“name.ccbi”);
CCDirector::sharedDirector()>replaceScene);
ccbReader
>release();
}
>
The problem is that I have to use the concrete loader name in the method. Any idea to overcome this problem?

If I’m not wrong, what you mean is to register all the scene loaders first. Am I right?

But this is not what I want. What I want is that I can registerCCNodeLoader dynamically because I don’t know all the Scene loader name first. For example, I have a config file which includes all the ccbi files. I only know the name of the scene load after I read the config file ( I remove the extension of the ccbi and add Loader as the loader class).

yes, that’s what I mean.
The loader files must be added to the project, why you don’t know all the loaders?

bagus flyer wrote:

If I’m not wrong, what you mean is to register all the scene loaders first. Am I right?
>
But this is not what I want. What I want is that I can registerCCNodeLoader dynamically because I don’t know all the Scene loader name first. For example, I have a config file which includes all the ccbi files. I only know the name of the scene load after I read the config file ( I remove the extension of the ccbi and add Loader as the loader class).

I need to dynamically load the ccbi file according to the setting in a config file. That’s why I only know the name.

My project is cross-application. Different application may have different scene so that the name of the loader maybe different that’s why I can’t register all the loaders.

Anyway I found a way to do it. But I need sometime to reorganize my code.