我在我的iOS应用程序中将cocos2d设置为子项目,运行最新版本(3.5)并定位iOS版本9.0+。我遇到的问题是当我从TestFairy下载并安装应用程序时,cocos2d屏幕是黑色的。我已经在模拟器和真实设备上调试了它,并且正确加载了cocos2d场景。
这是一个简单的手指绘画应用程序,它都是基于UIKit。 Cocos2d以标准方式添加到ViewController。相关代码是:
CCDirector *director = [CCDirector sharedDirector];
// If the director's OpenGL view hasn't been set up yet, then we should create it now. If you would like to prevent this "lazy loading", you should initialize the director and set its view elsewhere in your code.
if ([director isViewLoaded] == NO) {
director.view = [self createDirectorGLView];
[self didInitializeDirector];
}
else {
director.view.frame = [self getCanvasFrame];
[director.view setNeedsLayout];
[director.view layoutIfNeeded];
}
director.delegate = self;
// Add the director as a child view controller.
[self addChildViewController:director];
// Add the director's OpenGL view, and send it to the back of the view hierarchy so we can place UIKit elements on top of it.
[self.targetView addSubview:director.view];
[self.targetView sendSubviewToBack:director.view];
// Ensure we fulfill all of our view controller containment requirements.
[director didMoveToParentViewController:self];
createDirectorGLView
如下:
- (CCGLView *)createDirectorGLView {
_glView = [CCGLView viewWithFrame:[self getCanvasFrame]
pixelFormat:kEAGLColorFormatRGB565
depthFormat:0
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
return _glView;
}
我还有一个包含处理绘图的CCNode的场景。它是这样创建的:
@implementation IntroScene
- (id)init:(CGRect)frame {
self = [super init];
if (self) {
_canvas = [[LineDrawer alloc] init];
_canvas.contentSize = CGSizeMake(frame.size.width, frame.size.height);
_canvas.position = CGPointZero;
_canvas.anchorPoint = CGPointZero;
[self addChild:_canvas];
}
return self;
}
@end
当应用程序从TestFairy运行时,由于某些原因我无法访问控制台日志,所以我不能说那里发生了什么。然而,当我从Xcode调试时,一切看起来都正常,cocos2d画布正在加载/工作正常。我觉得这可能与项目归档的方式有关,但我不确定。有什么想法吗?
修改
所以我设法在设备的调试模式下重现它,我看到一些错误,我认为这些错误与使用OpenGL和cocos2d的TestFairy的屏幕录制有关。
2016-06-06 12:49:56.362 GraffiTab[5654:2941813] *** Assertion failure in -[CCRenderStateGL initWithBlendMode:shader:shaderUniforms:copyUniforms:], /Users/georgichristov/Documents/Workspace/Examples/GraffiTab/GraffiTab-iOS/GraffiTab/ExternalLibs/Cocos2d/cocos2d/CCRendererBasicTypes.m:356
2016-06-06 12:49:56.362 GraffiTab[5654:2941813] [visit] error CCRenderState: Blending mode is nil
2016-06-06 12:49:56.705 GraffiTab[5654:2941813] TestFairy: Initializing SDK version 1.7.6 (20160531-772d18b7)
2016-06-06 12:49:58.057 GraffiTab[5654:2941813] TestFairy: Session started successfully
2016-06-06 12:49:58.929 GraffiTab[5654:2941813] Please remove uses of SCRCException!