Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cocos2d and UINavigationController trouble

I'm working on an app where I'd like to use cocos2d in the app's home screen, but not elsewhere (in other places standard UIKit stuff is more appropriate). So, I've got my EAGLView set up as the root view in a UINavigationController, and when the user taps in the right place I push a new view controller onto the nav controller.

That's working great, so far. The cocos2d/chipmunk stuff in the home view is working great, pushing a new view controller works as expected.

But when I pop back to the home view, nothing's there. All I see is the window background and the navigation bar.

I set a breakpoint in the root view controller's -viewDidAppear: to see what's going on after the pop, and so far everything appears normal (or at least the same as it was before the push).

The push is just a bog-standard nav controller push. I'm not seeing any kind of memory warnings. Anyone have thoughts on what's going on?

There's a simple demo project that shows this behavior at http://cl.ly/1Q050s0h2k47032K1Y1N

This is based on the cocos2d+chipmunk project template. Tap on Grossini and a new view controller is pushed onto the stack. Tap the back button, and Grossini is gone.

And just to make it interesting, this problem only exists on an iOS device (I'm running 4.1), not in the simulator.

like image 844
Tom Harrington Avatar asked Dec 15 '10 05:12

Tom Harrington


1 Answers

I have solved your problem. You have to follow some steps in your code.

In RootViewController nib file change the view Identity from HomeView to UIView.

Create a Home View Object in the RootViewController Class

@interface RootViewController : UIViewController {
    HomeView *homeViewObj;
}

in RootViewController.m file in ViewDidLoad method add this code

homeViewObj = [[HomeView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:homeViewObj];

and replace this code in your ViewDidLoad method at required place.

CCDirector *director = [CCDirector sharedDirector];

    // attach the openglView to the director
    [director setOpenGLView:(EAGLView *)homeViewObj];

    [director setDeviceOrientation:kCCDeviceOrientationPortrait];
    [director setAnimationInterval:1.0/60];
    [director setDisplayFPS:YES];

Then the problem will be solved, All the best.

Regards,

Satya

like image 180
Satya Avatar answered Sep 30 '22 08:09

Satya