Search code examples
objective-ccocos2d-iphonecocosbuilder

Run a scene created with Cocos Builder in cocos2d 2.0, assertion failed


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.


Solution

  • 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.