多个 OpenGL 视图 (Cocos2D) [英] Multiple OpenGL views (Cocos2D)

查看:19
本文介绍了多个 OpenGL 视图 (Cocos2D)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:任何可以帮助我彻底解决此问题的人都将获得100 分赏金!!!

Note: Anyone who can help me properly fix this completely gets the 100 point bounty!!!

在我的应用程序中,我将 UIKit 和 Cocos2D 混合在一起,我使用 addSubview 和 removeFromSuperview 调用做了一些简单的自定义视图动画.我最近需要在我的应用程序中添加另一个 CCScene,以摆脱 Cocos2D 可以轻松处理的一些复杂的 UIKit 代码.所以我的应用程序中有一个基本视图,它是一个 UIViewController,上面有一些按钮.在这些按钮的后面是一个 CCGLView,Cocos2D 会做任何事情.这很好用.然后当我想去我的第二个视图控制器(让我们称之为我的游戏视图),在我做我的视图动画之后,viewdidload 被调用(那是我的导演初始化是为了第二个 CCScene)要么什么都没有发生,要么我在控制台中收到如下错误.现在在我的原始项目中,我得到了以下错误,在这个示例项目中没有任何反应.这些是错误:

In my application I am mixing UIKit with Cocos2D together, I do some simple custom view animations using addSubview and removeFromSuperview calls. I recently needed to add another CCScene to my app to get rid of some complicated UIKit code that Cocos2D can easily handle. So I have a base view in my app, it is a UIViewController with some buttons on it. Behind those buttons is a CCGLView which Cocos2D will do whatever on. That works great. Then when I want to go to my second view controller (lets call it my game view), after I do my view animations, the viewdidload gets called (thats where my director initialization is for the 2nd CCScene) and either nothing happens or I get errors like below in the console. Now in my original project the errors below are what I get, and in this sample project nothing happens. These are the errors:

OpenGL error 0x0501 in DrawSolidPolygon 104
OpenGL error 0x0502 in DrawSolidPolygon 104
OpenGL error 0x0501 in -[CCTextureAtlas drawNumberOfQuads:fromIndex:] 556
OpenGL error 0x0502 in -[CCTextureAtlas drawNumberOfQuads:fromIndex:] 556
OpenGL error 0x0502 in -[CCTextureAtlas drawNumberOfQuads:fromIndex:] 556
OpenGL error 0x0501 in -[CCParticleSystemQuad postStep] 411
OpenGL error 0x0506 in -[CCSprite draw] 532
OpenGL error 0x0502 in -[CCParticleSystemQuad draw] 434
OpenGL error 0x0502 in -[CCSprite draw] 532
OpenGL error 0x0502 in -[CCSprite draw] 532

现在,当我在原始项目中有一个场景时,不会发生这种情况,只有在我使用 2 个 CCScenes 时才会发生.因此,示例项目中的代码几乎是我原始项目的副本,因此其中的任何错误很可能会导致我在这里解决手头的问题,并希望摆脱那些 OpenGL 错误.

Now when I had one scene in my original project nothing like this happens, it only happens now that I am using 2 CCScenes. So the code in the sample project is a pretty much copy of my original project so anything wrong in there will most likely lead me to fix the issue at hand here and hopefully get rid of those OpenGL errors.

经过几个小时的测试和收集信息,我的问题似乎类似于:iOS 和多个 OpenGL 视图.我也看过这个链接:http://gamesfromwithin.com/using-multiple-opengl-views-and-uikit.然而,这两个链接对我来说都没有任何意义,因为我不知道如何将它与 Cocos2D 联系起来.我认为这整个问题是当前版本的 Cocos2D 的一个限制,但是如果有人可以下载我的项目并以某种方式将过去两个链接的修复应用到我的项目并完全修复它,那就太好了,并且可以解决我的所有问题!

After a few more hours of testing and gathering information, it seems that my issue is similar to: iOS and multiple OpenGL views. I have also seen this link: http://gamesfromwithin.com/using-multiple-opengl-views-and-uikit. However both of these links do not make any sense to me since I do not know how to relate it to Cocos2D. I think this whole issue is a limitation of the current version of Cocos2D but if someone can download my project and somehow apply these past two links' fixes to my project and fully fix it, that would be great and would fix all of my issues!

现在我项目中的 Cocos2D 版本是 2.0 版本可以下载的最新版本.如果有人愿意下载该项目并查看我做错了什么,我认为这将为我和遇到与我类似的问题的其他人解决问题.

Now the version of Cocos2D in my project is the latest available to download for the 2.0 version. If anyone would be nice enough to download the project and see what I am doing wrong I think this will solve the issue for me and others who are experiencing issues similar to mine.

下面的链接是我的问题示例项目的下载链接:http://www.gogofile.com/Default.aspx?p=sc&ID=634818635814123750_4340

The link below is a download link for the sample project with my issue: http://www.gogofile.com/Default.aspx?p=sc&ID=634818635814123750_4340

更新于 2012 年 9 月 3 日,我目前正在考虑联系 Cocos2D for iOS 的主要创建者 @riq.但是在我这样做之前,每个人都确定没有办法只拥有一个 CCGLView 并且我可以将它放在任何 UIViewController 中,因为从技术上讲,我不会使用两个视图,它只是控制器之间的一个共享视图.这种方式可行吗?

Update as of 9/3/12, I am currently thinking just to contact @riq, the main creator behind Cocos2D for iOS. However before I do so, is everyone sure there isn't a way to just have one CCGLView and I can just plop it in any UIViewController because technically I will not be using two views, it will just be one shared view between the controllers. Is this way possible?

推荐答案

好吧,我发现我几乎有 3 个选项:

Okay so I found out that I pretty much have 3 options:

1. @Riq 告诉我,2013 年 5 月发布的 2.2 版将支持多个 CCDirector.所以请玩等待游戏,直到 2.2 测试版发布.更新:2.1 最终版已于 6 月中旬发布,所以我猜 2.2 测试版应该会在一两个月内发布.

1. @Riq told me that support for multiple CCDirectors is coming in version 2.2 which will be released in May 2013. So play the waiting game until the 2.2 beta comes out. Update: 2.1 final has been out since the middle of June so I would guess that the 2.2 beta should be out within a month or two.

2. 只需要一个 UIViewController 来保存 CCGLView.然后,无论我需要什么 UIViewController 中的 glView,我都会使用 addChildViewController (iOS 5+),并且我会在切换视图时保留 UIViewController 并在那时也进行 replaceScene(也许在UIView 动画完成回调).我认为这种方式也可以,但我不确定它的效率.

2. Just have one UIViewController that holds the CCGLView. Then whatever UIViewController I need the glView in I would just use addChildViewController (iOS 5+) and I would just keep that UIViewController retained when I am switching views and just do replaceScene at that time too (maybe in the UIView animation completion callback). I think this way would work too but I am not sure of its efficiency.

编辑:我已经使用并全面测试了这个解决方案,它似乎工作得很好.我建议这样做直到 2.2 出来.我的应用以 60FPS 运行,看起来不错.

Edit: I have used and fully tested this solution and it seems to work great. I recommend doing this until 2.2 comes out. My app runs at 60FPS and looks good.

3. 我个人没有尝试过任何这些链接/拉取请求,@Riq 也没有,所以这将是我最后的选择.http://www.cocos2d-iphone.org/forum/topic/33480http://www.cocos2d-iphone.org/forum/topic/17821

这篇关于多个 OpenGL 视图 (Cocos2D)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆