Note that there are some explanatory texts on larger screens.

plurals
  1. POcocos2d 2.0-rc2: end the director and restart
    primarykey
    data
    text
    <p>I have a cocos2d powered game that uses UIKit menues, so I only use the framework for one viewcontroller, which is the game itself. Also, it only has one scene. Since cocos2d 2.0 the director itself is a <code>UIViewController</code> subclass, so I just push it in my <code>MenuViewController</code> when the user taps a start button:</p> <pre><code>-(void)startGameButtonPressed { CCDirectorIOS* director = (CCDirectorIOS *) [CCDirector sharedDirector]; // Create an CCGLView with a RGB565 color buffer, and a depth buffer of 0-bits self.glView = [CCGLView viewWithFrame:CGRectMake(0, 0, 480, 320) pixelFormat:kEAGLColorFormatRGB565 //kEAGLColorFormatRGBA8 depthFormat:0 //GL_DEPTH_COMPONENT24_OES preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0]; // attach the openglView to the director [director setView:glView]; [director runWithScene:[GameLayer scene]]; [director setDelegate:(id &lt;CCDirectorDelegate&gt;) [[UIApplication sharedApplication] delegate]]; [self.navigationController pushViewController:director animated:YES]; } </code></pre> <p>This works fine for the first time the method is called, when the user starts the first game. When the game is over, I call <code>[[CCDirector sharedDirector] end]</code>.</p> <p>Most of the director setup is done in the appDelegate (it's taken unchanged from the default Cocos2d template). I only put the <code>CCGLView</code> as a retained property into my <code>MenuViewController</code>, because otherwise the app crashes when <code>[[CCDirector sharedDirector] end]</code> is called and the <code>CCGLView</code> is not retained. I think that might be a cocos2d bug. In <code>[[CCDirector sharedDirector] end]</code> the framework calls <code>[self setView:nil]</code>, but it still tries to access the view later on (probably on another thread).</p> <p>The problem now is that on the second call of my method above (when the user wants to start another game from the menu), <code>startGameButtonPressed</code>, the director gets pushed but the screen remains black. The game is running and responding, I just don't see anything. Can someone please help me out with that?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload