Switching between Monogame and UIKit

≡放荡痞女 提交于 2019-12-05 06:59:22

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

1st option:

  1. When your app starts, start your Game class as you would a normal MonoGame game
  2. To display a controller present it modally over top of the game
  3. To return to the game, dismiss your modal controller

So for example, to show a controller:

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

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

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

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);

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!