Problems using UIKit and cocos2dx framework - how to instantiate and shutdown cocos2dx completely

Hello,

I am trying to port an existing iOS OpenGL game to cocos2dx. I don’t want to port/rewrite the game menu written with UIKit. Only the OpenGL part that resides in GameViewController has to be ported.
I have problems mapping the default cocos2dx layout that is used in the XCode-Templates to my project.

I want to create all cocos2dx related Objects when the GameViewController is instantiated, and I need to release all resources when the GameViewController is deallocated (going back to menu).

I tried to implement that and now I am facing multiple problems with my approach. The cocos2dx port generally behaves different than intended when I repeatedly go back and forth between the Menu(UIKit) and the GameViewController (with cocos2dx EAGLView):

  • The first time our new GameViewController is displayed, all CCNodes are displaced by some Pixels. After going back to the menu and opening a new instance of GameViewController the CCNodes are rendered at the correct positions.
  • Sometimes CCSprites are rendered as white boxes. This happens only at the second time we are instantiating the GameViewController.
  • We tried to render a colored box. For that we used a CCLayerColor. The first time the GameViewController is entered, the box is missing. On all further instantiations of GameViewController the box is visible.
  • The colored box sometimes is distorted.

Screenshots for all described errors are appended.

I’m using cocos2d-1.0.1-x-0.12.0

Obviously something is wrong with the way I use the cocos2dx framework. I created a XCode project that reveals the errors I just described, the screenshots are also taken from this project. The project was created with the cocos2dx XCode template with few additions. Maybe someone recognizes the error(s).

Generally I need to know how to instantiate the cocos2dx framework when GameViewController is instantiated and how to shutdown the cocos2dx framework completely when GameViewController is deallocated. Is this possible at all?

The TestProject is located at http://db.tt/Pxy2b2Lb


correct.jpeg (199.4 KB)


second_instantiation_distorted.jpeg (216.4 KB)


second_instatiation_ccsprite_missing.jpeg (196.6 KB)


first_instatiation_displaced.jpeg (182.6 KB)

Hi,
I’ve done exactly what you did and didn’t see any problem. My “game” is VERY simple so it might be a problem with more complex games or with the way you instantiate cocos2d-x.
If you still need help on this, you should post your code to instantiate/deinstantiate in order I can have a look at it.

Here is a tuto I just wrote http://jpsarda.tumblr.com/post/24983791554/mixing-cocos2d-x-uikit