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'
我怎么能解决这种错误的吗?
谢谢你的帮助。
这很奇怪,因为它在我的cocos2D项目中工作 – user2947788
直到你明白到底发生了什么才奇怪。 ;) – LearnCocos2D
大声笑这是真的,但我现在不从它来自 – user2947788