有没有适用于Windows通用应用程序的SharpDx模板?

3

我尝试使用SharpDx编写适用于Windows和Windows Phone 8.1的游戏。但是当我尝试将Windows Phone 8.1版本添加到已经存在的Windows 8.1游戏中时,出现了一些错误,应用程序无法正常工作。现在的问题是:是否有一个类似于XNA风格的SharpDx模板可用于Windows通用应用程序,就像我从SharpDx Visual Studio扩展中获得的仅适用于Windows 8.1的模板一样?

1个回答

6

目前还没有。

您应该打开一个问题(https://github.com/sharpdx/SharpDX/issues)并要求实现该功能。

但是在等待实现的过程中,您仍然可以开始操作 :D

以下是我尝试您的场景的方法:

然后在共享项目中

添加游戏:

using SharpDX;
using SharpDX.Toolkit;

namespace App1 {
    internal class MyGame : Game {
        private GraphicsDeviceManager _manager;

        public MyGame() {
            _manager = new GraphicsDeviceManager(this);
        }

        protected override void Draw(GameTime gameTime) {
#if WINDOWS_APP
    // desktop related
#elif WINDOWS_PHONE_APP
    // phone related
#endif
            GraphicsDevice.Clear(Color.Magenta);
            base.Draw(gameTime);
        }
    }
}

在您的桌面项目中: 添加一个 SwapChainPanel:
注:SwapChainPanel 是一种在 Windows 10 中使用 DirectX 的 UI 元素。
<Page
    x:Class="App1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <SwapChainPanel x:Name="SwapChainPanel1" />
    </Grid>
</Page>

运行你的游戏:

using Windows.UI.Xaml.Controls;

namespace App1 {
    /// <summary>
    ///     An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page {
        public MainPage() {
            InitializeComponent();
            Loaded += (sender, e) => {
                var myGame = new MyGame();
                myGame.Run(SwapChainPanel1);
            };
        }
    }
}

关于您的手机项目

请按照上述步骤执行:

<Page
    x:Class="App1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <SwapChainPanel x:Name="SwapChainPanel1" />
    </Grid>
</Page>

最后:
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace App1 {
    public sealed partial class MainPage : Page {
        public MainPage() {
            InitializeComponent();

            NavigationCacheMode = NavigationCacheMode.Required;
        }

        protected override void OnNavigatedTo(NavigationEventArgs e) {
            var myGame = new MyGame();
            myGame.Run(SwapChainPanel1);
        }
    }
}

你完成了!

非常感谢,这正是我所需要的。 - Matt126
有没有想过如何在WPF/Windows8.1应用程序中使用SharpDX裁剪图像区域? - Apoorv
@Aybe 我的台式电脑上显示了洋红色的屏幕,但是手机上没有显示。 - Ian Warburton
很抱歉,我实际上无法提供帮助,因为我从未在手机上使用过它。或许你可以在他们的网站上寻求帮助? - aybe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接