Reputation: 13073
Trying to integrate a Cocos2d view into a UIKit app. I'm getting this error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Do not initialize the TextureCache before the Director'
It seems to me that the Director is being initialized first.
AppDelegate didFinishLaunching:
// initialize cocos2d director
CCDirectorIOS* director = (CCDirectorIOS*)[CCDirector sharedDirector];
director.wantsFullScreenLayout = NO;
director.projection = kCCDirectorProjection2D;
director.animationInterval = 1.0 / 60.0;
director.displayStats = YES;
[director enableRetinaDisplay:YES];
NSArray* subviews = self.viewController.view.subviews;
for (int i = 0; i < subviews.count; i++)
{
UIView* subview = [subviews objectAtIndex:i];
if ([subview isKindOfClass:[CCGLView class]])
{
director.view = (CCGLView*)subview;
break;
}
}
View Controller viewDidLoad:
CCDirectorIOS* director = (CCDirectorIOS*)[CCDirector sharedDirector];
if (director.runningScene == nil)
{
[director runWithScene:[GameLayer scene]];
}
[director startAnimation];
And GameLayer:
+(id) scene {
CCScene *scene=[CCScene node];
CCLayer* layer=[GameLayer node];
[scene addChild:layer];
return scene;
}
-(id) init {
if ((self=[super init])) {
CCSprite *test = [CCSprite spriteWithFile:@"test.png"];
[self addChild:test];
CGSize size = [CCDirector sharedDirector].winSize;
test.position = CGPointMake(size.width / 2, size.height / 2);
}
return self;
}
What am I doing wrong?
Upvotes: 1
Views: 789
Reputation: 64478
I see it now: in didFinishLaunching you forgot to create the CCGLView instance and assign it to CCDirector. Your director is running without a view, and has no OpenGL context. Therefore textures can't be created.
The real issue is the misleading error message.
Upvotes: 2