Is cocosbuilder 3.0 supported by cocos2d-x?

Is cocosbuilder 3.0 supported by cocos2d-x?

Thanks. My application crashes when I load ccbi file generated by cocosbuilder 3.0.

Sorry. The cocosbuilder 3.0 ccb format works for cocos2d-x 2.10.

But I have a problem to catch the menu callback in my c*+ code. Here is what I did:

  1. Add a CCMenu and CCMenuItem in my MainMenuScene in CB. The selector is “onButtonPressed” and the target is “Document Root”.
  2. Publish it and add the ccbi to c*+ project resource.
  3. In my MainMenuScene (it’s load because the constructor is called), I have the following code:

SEL_MenuHandler MainMenuScene::onResolveCCBCCMenuItemSelector(CCObject * pTarget, const char * pSelectorName)
{
CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, “onButtonPressed”, MainMenuScene::onButtonPressed);
return NULL;
}

SEL_CCControlHandler MainMenuScene::onResolveCCBCCControlSelector(CCObject * pTarget, const char * pSelectorName)
{
return NULL;
}

bool MainMenuScene::onAssignCCBMemberVariable(CCObject * pTarget, const char * pMemberVariableName, CCNode * pNode)
{
return false;
}

void MainMenuScene::onButtonPressed(cocos2d::CCObject *pSender)
{
printf(“onButtonPressed”);
}

But my “onButtonPressed” function is never called. Can anybody advise what’s wrong in my implementation?

Thanks

Hi Bagus,

This just took me 3 days to figure out recently. What went wrong in my case was that the cocosbuilder files were js controlled. There is an option (don’t have my mac available at the moment) to disable the js controller in cocosbuilder. (it is a checkbox in a menu).

Uncheck the box. Then save the document first, and publish again. (yes, make sure you save the files first! )

Hope this helps for you.

Matthijs Spaans wrote:

Hi Bagus,
>
This just took me 3 days to figure out recently. What went wrong in my case was that the cocosbuilder files were js controlled. There is an option (don’t have my mac available at the moment) to disable the js controller in cocosbuilder. (it is a checkbox in a menu).
>
Uncheck the box. Then save the document first, and publish again. (yes, make sure you save the files first! )
>
Hope this helps for you.

Thanks for your reply. I disabled anything related to javascript in cocosbuilder (in project settings, in CCLayer, etc). And I clean everything and save and publish. Then clean and build my project. But I still got the same problem. My onButtonPressed is never been called.

My cocosbuild is 3.0 (I built from the latest source code) and my cocos2d-x is cocos2d-2.1beta3-x-2.1.0. Any idea? Thanks

Matthijs Spaans wrote:

Hi Bagus,
>
This just took me 3 days to figure out recently. What went wrong in my case was that the cocosbuilder files were js controlled. There is an option (don’t have my mac available at the moment) to disable the js controller in cocosbuilder. (it is a checkbox in a menu).
>
Uncheck the box. Then save the document first, and publish again. (yes, make sure you save the files first! )
>
Hope this helps for you.

Yes. You’re right.It works after I unchecked the “JavaScript Controlled” in “Document” menu. Thank you so much.

This is a bug. Am I right?

I think it’s an issue of CocosBuilder.

James Chen wrote:

I think it’s an issue of CocosBuilder.

I am using Cocosbuilder 3.0alpha4 together with cocos2d-2.1rc0-x-2.1.3.
I unchecked the Javascript Controlled option in the mentioned locatiobs in Cocosbuilder, but still I keep getting this notice when running the app:
Skipping selector ‘pressedPlay:’ since no CCBSelectorResolver is present .

I tried lots of different settings (Document root / Owner, with colon ,without colon) but my method is never called.
Did you guys use different versions, because it works for you?

Don’t change anything of CCMenuItemImage’s ‘Code Connections’

Twan Claassen wrote:

James Chen wrote:
> I think it’s an issue of CocosBuilder.
>
I am using Cocosbuilder 3.0alpha4 together with cocos2d-2.1rc0-x-2.1.3.
I unchecked the Javascript Controlled option in the mentioned locatiobs in Cocosbuilder, but still I keep getting this notice when running the app:
Skipping selector ‘pressedPlay:’ since no CCBSelectorResolver is present .
>
I tried lots of different settings (Document root / Owner, with colon ,without colon) but my method is never called.
Did you guys use different versions, because it works for you?

I’m currently using Cocosbuilder 3.0 alpha 5 with cocos2d-x 2.1.4 and I’m also getting the same issue where my selectors don’t get called even though I have mapped them. I have the Javascript Controlled option unchecked as well. However, one thing I did noticed comparing Alpha4 and Alpha5 in the inspector view where it says Code Connection. It shows “JS Controller” instead of “Custom class” and I can’t find where I can set custom class.

I put a CCLOG inside of onNodeLoaded(cocos2d::CCNode * pNode, cocos2d::extension::CCNodeLoader * pNodeLoader) and it looks like it doesn’t get called, so I’m assuming the loader isn’t called.

I’m assuming there has to be a Custom Class parameter in the CCLayer properties that is now showing in cocosbuilder 3 alpha 5.

I switched back to Cocosbuilder 3 Alpha 4 and created a new project with “JavaScript based project” uncheck, and I was able to see the custom class property in the inspector, and it did ran my menu item selector, so I think it might be a bug in Cocosbuilder 3 Alpha 5 where the custom class property does not show up.

Actually I realized I got mixed up with “JavaScript based project” which is in the project properties vs “Javascript controlled” in the documents menu. It turns out it wasn’t an alpha 5 vs alpha 4 issue, it is working on alpha 5.

Great you got it working! I never managed and went back to coding interfaces and animations by hand… :frowning:

Can you please tell me what steps you take exactly to make a new project that calls the selector succesfully? Would love to hear that :slight_smile:

Hi Twan,

I’m currently using Cocosbuilder 3 alpha 5. The steps I did was:

File > New Project
select a path where you want to create the ccb project

File >Project Settings…
Uncheck the Javascript based project and press Done.

File > Publish Settings…
Check flatten path when publishing
Check publish only ccb-files

File > New > Interface File…
Once the new interface is opened

Documents >Uncheck the JavaScript controlled
You will noticed when you select the base layer
On the left panel i.e. the inspector, under the Code Connections section:
It will change from JS Controller to custom class
How you can set the custom class and create the custom class in your xcode project etc.
Make sure when you use a selector it has the Document Root selected under Target for your menu item or control.

Once you can set a custom class then you can follow this tutorial to set up the selectors and custom classes and loader in code.
http://www.plungeinteractive.com/blog/using-cocosbuilder-on-cocos2d-x-games/

Then it should just work. :slight_smile:

I’m thinking about posting a video on youtube to show other people because it took me a week to discover looking through the forum and documentation, but that depends if I have the resources to do the recording.

I hope that helps.

Thanks for your explanation! :slight_smile:

However the code from this tutorial: http://www.plungeinteractive.com/blog/using-cocosbuilder-on-cocos2d-x-games/
Does not compile :frowning: I am using Cocos2d-x 2.1.4… Did this work for you or did you fix the code yourself?

Hi, I’m having trouble with the js controlled setting, I followed all the steps Lawrence posted, but when I try to load my ccbi on my cocosdx code it still set the jscontrolled variable to true.

Actually, after working with Cocobuilder 3, I noticed that I don’t really need to enable “flatten path when publishing”, because I realize there was an issue with having it load a ccb custom nodes in subfolders, and it runs into path issues.

Also, the documentation also helps
https://github.com/cocos2d/CocosBuilder/blob/master/Documentation/4c.20Connecting20with%20cocos2d-x.md
especially the “Setting scale and design size”

In the AppDelegate::applicationDidFinishLaunching

CCSize designSize = CCSizeMake(320, 480);
CCSize resourceSize = CCSizeMake(320, 480);
CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();

std::vector searchPaths;
std::vector resDirOrders;

TargetPlatform platform = CCApplication::sharedApplication()->getTargetPlatform();
if (platform == kTargetIphone || platform == kTargetIpad)
{
    searchPaths.push_back("Published-iOS"); // Resources/Published-iOS
    CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);

    if (screenSize.height > 768)
    {
        resourceSize = CCSizeMake(1536, 2048);
        resDirOrders.push_back("resources-ipadhd");
    }
    else if (screenSize.height > 640)
    {
        resourceSize = CCSizeMake(768, 1536);
        resDirOrders.push_back("resources-ipad");
    }else if (screenSize.height > 480)
    {
        resourceSize = CCSizeMake(640, 960);
        resDirOrders.push_back("resources-iphonehd");
    }
    else
    {
        resDirOrders.push_back("resources-iphone");
    }

    CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders);
}
else if (platform == kTargetAndroid || platform == kTargetWindows)
{
    if (screenSize.height > 960)
    {
        resourceSize = CCSizeMake(640, 960);
        resDirOrders.push_back("resources-large");
    }
    else if (screenSize.height > 480)
    {
        resourceSize = CCSizeMake(480, 720);
        resDirOrders.push_back("resources-medium");
    }
    else
    {
        resourceSize = CCSizeMake(320, 568);
        resDirOrders.push_back("resources-small");
    }

    CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders);
}
pDirector->setContentScaleFactor(resourceSize.width/designSize.width);

CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionShowAll);

The key is resDirOrders.push_back( … ) if that was not specified you might run into issues where it cannot find where the ccbi. That was one common issue for me when I was using cocosbuilder 3.

@bagusflyer did you set your custom class for layer ?