gpt4 book ai didi

ios - 集成到 UIKit 应用程序时来自 Cocos2d 的 TextureCache 错误

转载 作者:行者123 更新时间:2023-11-29 11:02:41 26 4
gpt4 key购买 nike

尝试将 Cocos2d View 集成到 UIKit 应用程序中。我收到此错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Do not initialize the TextureCache before the Director'

在我看来,首先要初始化 Director。

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];

和游戏层:

+(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;
}

我做错了什么?

最佳答案

我现在明白了:在 didFinishLaunching 中,您忘记创建 CCG​​LView 实例并将其分配给 CCDirector。您的导演在没有 View 的情况下运行,并且没有 OpenGL 上下文。因此无法创建纹理。

真正的问题是误导性的错误消息。

关于ios - 集成到 UIKit 应用程序时来自 Cocos2d 的 TextureCache 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15168869/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com