【问题标题】:Cocos2d Project Within UINavigationControllerUINavigationController 内的 Cocos2d 项目
【发布时间】:2011-09-26 01:52:29
【问题描述】:

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

*我想将游戏附加到一个视图控制器,它是我的 UINavigationController 的一个元素。如果我只是从根视图控制器运行游戏,则下面的代码可以工作,但由于某种原因,如果我尝试从单独的视图控制器运行游戏,它会给我一个“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 VC] --> [游戏控制器:启动游戏]

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

【问题讨论】:

  • 我认为[[Director sharedDirector] attachInView:(UIView *) withFrame:(CGRect) 可能与它有关。但是,上面的代码在不是 rootviewcontroller 的视图控制器中不起作用..
  • 你知道在导航控制器中使用 cocos2d 的任何资源吗?

标签: iphone ios uiviewcontroller uinavigationcontroller cocos2d-iphone


【解决方案1】:

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

[[Director sharedDirector] end]

结束所有正在运行的场景并将项目从其窗口或视图中分离出来。

由于我需要游戏全屏运行并使用导航控制器,因此我只是使用下面的方法使其工作。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 2013-05-04
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多