开发者

Cocos2d Project Within UINavigationController

I know there are a few questions on this already - but none pertain to my problem. I'm trying to attach part of an old Cocos2d game to my app via a UINavigationController. (the main point of this is so I can pop back to my root view controller when I want to return to the main screen of my app. I think there's a very straightforward solution to this..

*I want to attach the game to a view controller that is an element of my UINavigationController. The below code works if I simply run the game from my root view controller, but for some reason it gives me an "EXC_BAD_ACCESS Director @synchronized" error if I try to run the game from a separate view controller.

Currently, I am using the following code to initiate my game from the main screen (root VC) of my app (via a button tap).

MyAppDelegate *appDel开发者_如何转开发egate = [[UIApplication sharedApplication] delegate];
UIWindow *window = appDelegate.window;

[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent];
Director *director = [Director sharedDirector];
[director setPixelFormat:kRGBA8];
[director attachInView:self.view withFrame: window.frame];
[director setAnimationInterval:1.0/kFPS];
[Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888]; 

Scene *scene = [[Scene node] addChild:[Game node] z:0];
[director runWithScene: scene];

Which runs the game fine. However, I need some way to get back to app's main screen once I finish the game. How do I open init this game WITHIN a view controller that's not the root view controller?

[ROOT VC] --> [GAME CONTROLLER: INITIATES THE GAME]

I'm very new to Cocos2d.. Any help is extremely appreciated!


I resolved this issue quite easily by using the Cocos2d Director method:

[[Director sharedDirector] end]

which ends all running scenes and detaches the project from its window or view.

Since I was needing the game to run full screen and was using a navigation controller, I just used the below to make it work.

    [appDelegate.navigationController setNavigationBarHidden:NO animated:YES];
    [appDelegate.navigationController setNavigationBarHidden:YES animated:YES];

Note: You can call any Director methods from anywhere in your project by invoking the [Director sharedDirector] reference. Hope this helps others and can save some time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜