c# - 是否有适用于 Windows 通用应用程序的 SharpDx 模板?

标签 c# directx windows-phone-8.1 win-universal-app sharpdx

我尝试使用 SharpDx 为 Windows 和 Windows Phone 8.1 编写游戏。但是当我尝试将 Windows Phone 8.1 版本添加到我现有的 Windows 8.1 游戏时,我遇到了一些错误并且应用程序无法运行。现在的问题是:是否有适用于 Windows 通用应用程序的 XNA 风格的 SharpDx 模板,就像我为我唯一的 Windows 8.1 游戏(来自 SharpDx Visual Studio 扩展)获得的模板一样?

最佳答案

不,还没有。

你应该做的是打开一个问题(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:

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

你完成了!

关于c# - 是否有适用于 Windows 通用应用程序的 SharpDx 模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25456492/

相关文章:

c# - MessageDialog 在 Windows Phone 8.1 上用 3 个命令中断

c# - NV_STEREO_IMAGE_SIGNATURE 和 DirectX 10/11(nVidia 3D Vision)

directx - Direct2D Direct3d11 互操作 - 设备会丢失吗?

c# - 如何在给定视频 ID 的情况下获取 youtube channel ID 和名称

c# - 将文本文件解析为 CSV C#

c++ - 围绕一个点(行星)向不同方向移动

c# - 获取SD卡中的文件夹和文件列表

C# CopyToDataTable 方法不起作用

c# - 当我尝试保存图像时收到错误 "A generic error occurred in GDI+."

c# - TCP 表现怪异