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.
CCSprites are rendered as white boxes. This happens only at the second time we are instantiating the
- 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)