iphone - UINavigationController 中的 Cocos2d 项目

标签 iphone ios uiviewcontroller uinavigationcontroller cocos2d-iphone

我知道已经有一些关于此的问题 - 但没有一个与我的问题有关。 我正在尝试通过 UINavigationController 将旧 Cocos2d 游戏的一部分附加到我的应用程序。 (这样做的要点是,当我想返回到我的应用程序的主屏幕时,我可以返回到我的 Root View Controller 。我认为对此有一个非常简单的解决方案..

*我想将游戏附加到作为我的 UINavigationController 元素的 View Controller 。如果我只是从我的 Root View Controller 运行游戏,下面的代码可以工作,但出于某种原因,如果我尝试从单独的 View Controller 运行游戏,它会给我一个“EXC_BAD_ACCESS Director @synchronized”错误。

目前,我正在使用以下代码从我的应用程序的主屏幕(根 VC)启动我的游戏(通过点击按钮)。

MyAppDelegate *appDelegate = [[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];

这可以很好地运行游戏。但是,我需要一些方法才能在完成游戏后返回到应用程序的主屏幕。如何在不是 Root View Controller 的 View Controller 中打开这个游戏?

[ROOT VC] --> [游戏 Controller :启动游戏]

我是 Cocos2d 的新手。非常感谢任何帮助!

最佳答案

我使用 Cocos2d Director 方法很容易地解决了这个问题:

[[Director sharedDirector] end]

这将结束所有正在运行的场景并将项目与其窗口或 View 分离。

因为我需要游戏全屏运行并使用导航 Controller ,所以我只使用下面的方法让它工作。

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

注意:您可以通过调用 [Director sharedDirector] 引用从项目中的任何位置调用任何 Director 方法。希望这可以帮助其他人并节省一些时间。

关于iphone - UINavigationController 中的 Cocos2d 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7549961/

相关文章:

ios - 如何创建一个发出键盘高度的 RxSwift Observable?

ios - 如何检查 iOS Swift 2 中的 WiFi 是否打开或关闭?

ios - View Controller 更改时的间隙

ios - 将导航 Controller 限制为一组 UIViewController

ios - 为 Debug-iphoneos 构建时如何调试断言

iphone - 如何手动删除 UITableView 中的一行?

iOS:信标检测需要很长时间

iphone - Xcode - 从不同的 View 更新 ViewController 标签文本

iphone - 如何在 iPhone sdk 中序列化一个简单的对象?

ios - TableView 单元格操作