0

I am following this tutorial to try to run a scene created in Cocos Builder (the tutorial does it with a detailed "cat jump" project, but it's not important for me to do it the same way). I am doing it with cocos2d 2.0 instead of 2.1 as done in the tutorial because with the version 2.1 I get some syntax errors in the CCBReader class, which instead compiles fine with cocos2d 2.0 .

I've followed the guide until the "The Main Event" paragraph, and the app should work. For who doesn't want to follow the guide, this is what I've done so far:

  1. Correctly dragged CCBReader and CCControlExtension folder to the xcode project;
  2. Dragged all the resources from the Cocos Builder project folder to xcode project's resources;
  3. Created a group named "scenes" in which I dragged my MainMenuScene.ccbi file;
  4. Replaced the line of code that pushes the scene with this one:

-

[director_ runWithScene: [CCBReader sceneWithNodeGraphFromFile: @"MainMenuScene.ccbi"]];

I even tried this:

[director_pushScene: [CCBReader sceneWithNodeGraphFromFile: @"MainMenuScene.ccbi"]];

With no luck. When I run the app an assertion fails:

enter image description here

I've found the main reason of the problem, but I don't know how to fix it. The problem is that in a CCBReader method:

+ (CCScene*) sceneWithNodeGraphFromFile:(NSString *)file owner:(id)owner
{
    return [CCBReader sceneWithNodeGraphFromFile:file owner:owner parentSize:[[CCDirector sharedDirector] winSize]];
} 

This method returns nil, then this other method gets called:

+ (CCScene*) sceneWithNodeGraphFromFile:(NSString *)file owner:(id)owner parentSize:(CGSize)parentSize
{
    CCNode* node = [CCBReader nodeGraphFromFile:file owner:owner parentSize:parentSize];
    CCScene* scene = [CCScene node];
    [scene addChild:node];
    return scene;
}

Where node is nil, and this causes the assertion fail, but I don't know why sceneWithNodeGraphFromFile:owner: returns nil, I have a file named "MainMenuScene.ccbi" in my project, and it's also copied into the app the bundle, so I don't see a reason for this method to return nil. I would really appreciate if someone could show me how to fix this problem, or to show me some alternative way to import a Cocos Builder scene into a cocos2d 2.0 project.

3 Answers 3

0

put a breakpoint on this line:

CCNode* node = [CCBReader nodeGraphFromFile:file owner:owner parentSize:parentSize];

then look at all of the variables in the variable view then step into that method, you will see why that is returning nil, probably wrong file path, or wrong type, URL for path etc

1
  • owner is nil, but I don't know if this is ok for who designed CCBReader. file is "MainMenuScene.ccbi", I even tried replacing it with the full path + filename (using NSBundle), but I'm still getting the assertion failure. Jun 7, 2013 at 16:04
0

Ramy, seens like the file isn`t compiled in your project. check if the file "MainMenuScene.ccbi" is on your Bundle Resources.

You can check it in your project > Build Phases > Copy Bundle Resources...

Or you can select the file in your project tree and check "Target Membership" on right panel (Utilities)

2
  • The root node in your ccb file (on CocosBuilder) have some class associated with then?
    – Bivis
    Jun 7, 2013 at 19:48
  • 1
    Yes, that class is named "MainMenuLayer", and I have it inside the project. I solved the problem dragging into the xcode project the "ccbResources" folder from the Cocos Builder project. Jun 7, 2013 at 22:01
0

It turned out that I forgot to add the directory "ccbResources" from the Cocos Builder project to xcode. Now with this folder added the entire project works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.