Search code examples
windows-phone-8windows-phone-8.1monogame

How to setup project for Monogame + Windows 8.1?


I'm in the middle of app development with Monogame, and I wanted to add a project for Windows Phone. I have a device with Windows Mobile 8.1 for testing, and I'm using Monogame 3.5 (latest) + VS 2015. But how do I create a project?

The templates for Monogame have several platforms, but the only one for Windows Mobile seems to be Windows 10 Uniwersal Project (UWP). I doubt this would run on WM8.1. Or would it? If not, how do I create the project this otherwise?

Update:

Did more research on this and it seems you need to have minimum Windows 8.1 on your dev PC to develop for Windows Phone 8.1:

https://www.visualstudio.com/en-us/products/visual-studio-2015-compatibility-vs.aspx

So I guess I will just support Android and iOS like all other mobile apps.


Solution

  • Variant 1:

    • Create win phone 8.1 project
    • Add NuGet package MonoGame.Framework.WindowsPhone81 (NuGet)
    • Add standart Game1.cs source code file from Monogame templates
    • Add in MainPage.xaml.cs

      using MonoGame.Framework;
      
    • Change in MainPage.xaml.cs

      public sealed partial class MainPage : SwapChainBackgroundPanel
      {
          readonly Game1 _game;
      
          public MainPage(string launchArguments)
          {
              this.InitializeComponent();
      
              _game = XamlGame<Game1>.Create(launchArguments, Window.Current.CoreWindow, this);
          }
      }
      
    • Change MainPage.xaml (MyGame - default project namespace)

      <SwapChainBackgroundPanel
          x:Class="MyGame.MainPage"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="using:MyGame"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          mc:Ignorable="d">
      
          <Grid >
      
          </Grid>
      </SwapChainBackgroundPanel>
      
    • Change App class in App.xaml.cs

      protected override void OnLaunched(LaunchActivatedEventArgs args)
      {
          var gamePage = Window.Current.Content as MainPage;
      
          if (gamePage == null)
          {
              gamePage = new MainPage(args.Arguments);
      
              if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
              {
              }
      
              Window.Current.Content = gamePage;
          }
      
          Window.Current.Activate();
      }
      
      private void OnSuspending(object sender, SuspendingEventArgs e)
      {
          var deferral = e.SuspendingOperation.GetDeferral();
      
          deferral.Complete();
      }
      
    • Add Content.mgcb

    • Add monogameplatform to project file (.csproj) into PropertyGroup section

      <PropertyGroup>
      ...
      <MonoGamePlatform>WindowsStoreApp</MonoGamePlatform>
      <MonoGameContentBuilderExe>
      </MonoGameContentBuilderExe>
      ...
      </PropertyGroup>
      
    • Add next line to project file (.csproj) into Project section

      <Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
      

    Variant 2: use tool from Protobuild.org