【发布时间】:2012-02-23 07:22:38
【问题描述】:
我在将 cocos2d 场景集成到现有应用程序的选项卡中时遇到了一些麻烦。 我使用 cocos2d 附带的 Xcode 模板开发了场景,效果很好,但是当我尝试在现有应用程序上加载相同的场景时,结果却是黑屏。
这是我加载链接到选项卡的 UIViewController 时运行的代码
-(void)viewDidLoad {
director = [CCDirector sharedDirector]; //declared in the header file
//declared in the header file, sized as whole screen minus the tab bar
coolview = [CCGLView viewWithFrame:CGRectMake(0,0, 320,321) pixelFormat:kEAGLColorFormatRGB56 depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0];
[director setView:coolview];
[self setView:coolview];
[director setAnimationInterval:1.0/60];
[director setDelegate:self];
[director setProjection:kCCDirectorProjection2D];
[director runWithScene:[HelloWorldLayer scene]];
}
知道为什么我应该黑屏吗?我错过了什么?
HelloWorld 层中的代码已执行,对象已实例化,但似乎它们没有被渲染。
我还收到以下反馈:
OpenGL error 0x0501 in -[CCShaderCache loadDefaultShaders] 174
OpenGL error 0x0501 in -[CCTextureAtlas initVAO] 167
OpenGL error 0x0501 in -[CCDirector setView:] 308
OpenGL error 0x0501 in -[CCTextureAtlas initVAO] 167
但我一直无法找到错误代码的含义。 我正在使用 cocos2d 版本 2。
提前感谢您的帮助 卢卡
一点更新:1.0.1 版本不会出现此问题,将 CCGLView 替换为 EAGLView。 所以我假设这可能是这个版本的一个小错误。
很遗憾,我无法切换到 1.0.1,因为我需要一些 box2d v2.2 的功能,而这些功能只有 cocos2d v2.0 才能提供。 我正在尝试使 box2d v2.2 与 cocos v1.0.1 一起使用,但它变得非常丑陋!
有人知道我如何在 2.0 中修复它,或者至少为我指明正确的方向吗?问题可能出在哪里?在 CCDirector 或 CCGLView 中?
谢谢 卢卡
【问题讨论】:
-
在您的代码中看起来很可疑的一件事是“[director runWithScene:[HelloWorldLayer scene]];”这一行CCLayer 没有场景属性。为什么要将 CCScene 对象放在图层中?你的场景中真的有任何东西要渲染吗?我在一个测试应用程序中尝试了你的代码,它运行良好。
标签: iphone opengl-es cocos2d-iphone