UINavigationController 中的 Cocos2d 项目
我知道已经有一些关于此的问题 - 但没有一个与我的问题有关。 我正在尝试通过 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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用 Cocos2d Director 方法很轻松地解决了这个问题:
它结束所有正在运行的场景并将项目与其窗口或视图分离。
由于我需要游戏全屏运行并使用导航控制器,所以我只是使用下面的方法来使其工作。
注意:您可以通过调用 [Director sharedDirector] 引用从项目中的任何位置调用任何 Director 方法。希望这可以帮助其他人并节省一些时间。
I resolved this issue quite easily by using the Cocos2d Director method:
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.
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.