Note: Anyone who can help me properly fix this completely gets the 100 point bounty!!!
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
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.
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!
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.
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
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?
Okay so I found out that I pretty much have 3 options:
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. 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.
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. I personally have not tried any of these links/pull requests and neither has @Riq so this would be my last option. http://www.cocos2d-iphone.org/forum/topic/33480 AND http://www.cocos2d-iphone.org/forum/topic/17821
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With