UINavigationController 中的 Cocos2d 项目

发布于 2024-12-06 14:12:41 字数 985 浏览 0 评论 0原文

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

*我想将游戏附加到视图控制器是我的 UINavigationController 的一个元素。如果我只是从根视图控制器运行游戏,下面的代码就可以工作,但由于某种原因,如果我尝试从单独视图 但是

目前,我正在使用以下代码从应用程序的主屏幕(根 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];

我需要某种方法来返回应用程序的主屏幕。完成游戏后如何在不是根视图控制器的视图控制器中打开 init 这个

游戏 Cocos2d..非常感谢任何帮助!

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 *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];

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

路还长,别太狂 2024-12-13 14:12:41

我通过使用 Cocos2d Director 方法很轻松地解决了这个问题:

[[Director sharedDirector] end]

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

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

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文