在Monogame和UIKit之间切换 [英] Switching between Monogame and UIKit

查看:68
本文介绍了在Monogame和UIKit之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索,但是似乎找不到适合我要尝试的解决方案,而我几乎要问这是否有可能.

I've been searching and searching but can't seem to find a solution that works for what I'm trying to do, and I'm almost at the point where I have to ask if it is even possible.

我正在使用Xamarin Studio开发iOS应用.我将几个不同的屏幕设置为UIViewControllers,它们运行良好.但是,该应用程序的关键是游戏,我想使用Monogame,就像我以前使用它并喜欢使用它一样.

I'm using Xamarin Studio to develop an iOS app. I have a few different screens set up as UIViewControllers and they are working well. The crux of the app, however, is a game and I want to use Monogame as I've used it before and enjoyed working with it.

基本上,我必须从UIViewController切换到Game类.我可以通过简单地创建一个新的Game对象并调用Run()来做到这一点,但是我无法弄清楚何时需要退出游戏并将控制权返回给UIViewController.

Basically, I have to switch from a UIViewController to the Game class. I am able to do this by simply creating a new Game object and calling Run(), but I can not figure out how to get out of the Game when I need to and return control back to the UIViewController.

有人在应用程序中做到了吗?我已经尽我所能想到的一切,但似乎没有办法解决.可能吗?还是我需要重做它,以便Monogame处理所有内容,甚至包括应用程序中不属于实际游戏的所有其他内容?

Has anybody done this in an app? I've tried everything I can possibly think of, but nothing seems to do the trick. Is it even possible? Or will I need to redo it so that Monogame handles everything, even all of the other stuff in the app that isn't part of the actual game?

谢谢!

推荐答案

我认为有几种技巧可以在不修改MonoGame的情况下实现.

There are a couple hacky ways I feel this will work without modifying MonoGame.

第一个选项:

  1. 应用启动后,像正常的MonoGame游戏一样启动Game
  2. 要显示控制器,请将其以模态形式显示在游戏上方
  3. 要返回游戏,请关闭模态控制器

例如,要显示一个控制器:

So for example, to show a controller:

var gameController = game.Services.GetService(typeof(UIViewController)) as UIViewController;
gameController.PresentViewController(new YourController(), true, null);

然后,您只需调用DismissViewController即可将其隐藏.我已经用它来实现Game Center的东西.

Then you can just call DismissViewController to hide it. I've used this for implementing Game Center stuff.

遗憾的是,如果要在UIKit控制器之后的 中展示MonoGame游戏,则必须修改MonoGame的工作方式.

Sadly, you will have to modify how MonoGame works if you want to show your MonoGame game after a UIKit controller.

另一个选择是基本上在MonoGame视图的顶部添加UIView.像这样:

Another option is to basically add a UIView on top of your MonoGame's view. Something like this:

var gameController = game.Services.GetService(typeof(UIViewController)) as UIViewController;
var view = new YourView();
gameController.View.AddSubview(view);

如果您选择此路线,则需要添加一些逻辑来暂停游戏.我以前在iAd等设备上使用过此选项.您也可以在其他控制器的视图中执行此操作,例如上面的标签控制器示例.

You'll need to add some logic to pause the game if you take this route. I've used this option before for iAd, etc. You could also do this with other controllers' views, like your tab controller example above.

这篇关于在Monogame和UIKit之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆