2014-01-10 83 views
0

我已經創建了一個'cocos2D'遊戲,以及一些菜單等等,在「classic」'objective-C'中。所以,你可以理解,我只能創建一個項目。我已經將沒有問題的cocos2d的庫,但現在,當我想運行我cocos2D上文件到我的「的UIViewController」,我有一些麻煩:將cocos2D文件添加到UIViewcontroller中

#import "ViewController.h" 

@interface ViewController() 

@end 

#import "HelloWorldLayer.h" 

@implementation ViewController 

+(CCScene *) scene 
{ 
    // 'scene' is an autorelease object. 
    CCScene *scene = [CCScene node]; 

    // 'layer' is an autorelease object. 
    HelloWorldLayer *layer = [HelloWorldLayer node]; 

    // add layer as a child to scene 
    [scene addChild: layer]; 

    // return the scene 
    return scene; 
} 

- (void)viewDidLoad 
{ 
    self.view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)]; 

    [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. 

    CCDirector *director = [CCDirector sharedDirector]; 
    CCGLView *glView = [CCGLView viewWithFrame:CGRectMake(-100, -50, 480, 480) 
            pixelFormat:kEAGLColorFormatRGBA8 
            depthFormat:0]; 
    glView.opaque = NO; 
    [director setView:glView]; 
    [director runWithScene:[HelloWorldLayer scene]]; 

} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

正如你可以看到,我的「的UIViewController」命名視圖控制器,和我的cocos2D文件HelloWorldLayer。

我已經看到,在一個cocos2D項目的Introlayer文件中,HelloWorldLayer沒有初始化。我嘗試做相同的代碼來運行我的場景,但它不工作,給我的錯誤:

Assertion failure in -[HelloWorldLayer addChild:], /Users/jerry-fr/Desktop/TestCocos2DIntegration/TestCocos2DIntegration/libs/cocos2d/CCNode.m:382 

2014-01-10 23:59:50.647 TestCocos2DIntegration[30030:15203] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Argument must be non-nil' 

我怎麼能解決這種錯誤的嗎?

謝謝你的幫助。

回答

0

addChild:HelloWorldLayer的無對象。設置全局異常斷點(請參閱xcode幫助)並檢查callstack以追溯問題。

+0

這很奇怪,因爲它在我的cocos2D項目中工作 – user2947788

+0

直到你明白到底發生了什麼才奇怪。 ;) – LearnCocos2D

+0

大聲笑這是真的,但我現在不從它來自 – user2947788

相關問題