如何为 Monogame + Windows 8.1 设置项目?

How to setup project for Monogame + Windows 8.1?

我正在使用 Monogame 开发应用程序,我想为 Windows Phone 添加一个项目。我有一台带有 Windows Mobile 8.1 的设备用于测试,我使用的是 Monogame 3.5(最新)+ VS 2015。但是如何创建项目?

Monogame 的模板有多个平台,但 Windows Mobile 的唯一模板似乎是 Windows 10 Uniwersal Project (UWP)。我怀疑这会在 WM8.1 上 运行。或者会吗?如果没有,我该如何创建这个项目?

更新:

对此进行了更多研究,看来您的开发 PC 上至少需要 Windows 8.1 才能为 Windows Phone 8.1 开发:

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

所以我想我会像所有其他移动应用程序一样支持 Android 和 iOS。

变体 1:

  • 创建 win phone 8.1 项目
  • 添加 NuGet 包 MonoGame.Framework.WindowsPhone81 (NuGet)
  • 从 Monogame 模板添加标准 Game1.cs 源代码文件
  • 加入MainPage.xaml.cs

    using MonoGame.Framework;
    
  • 变化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);
        }
    }
    
  • 更改MainPage.xaml(MyGame - 默认项目命名空间)

    <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>
    
  • 在App.xaml.cs

    中更改应用class
    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();
    }
    
  • 添加Content.mgcb

  • 将 monogameplatform 添加到项目文件 (.csproj) 的 PropertyGroup 部分

    <PropertyGroup>
    ...
    <MonoGamePlatform>WindowsStoreApp</MonoGamePlatform>
    <MonoGameContentBuilderExe>
    </MonoGameContentBuilderExe>
    ...
    </PropertyGroup>
    
  • 将项目文件 (.csproj) 的下一行添加到项目部分

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

变体 2: 使用来自 Protobuild.org

的工具