对于Windows通用应用程序,是否有SharpDx模板?

Cri*_*126 3 c# directx sharpdx windows-phone-8.1 win-universal-app

我试图用SharpDx为Windows和Windows Phone 8.1编写游戏.但是当我尝试将Windows Phone 8.1版本添加到我已经存在的Windows 8.1游戏时,我收到一些错误并且应用程序不起作用.现在的问题是:对于Windows通用应用程序,是否存在XNA样式的SharpDx模板,例如我为我唯一的Windows 8.1游戏(来自SharpDx Visual Studio扩展)获得的模板?

Ayb*_*ybe 5

不,还没有.

你应该做的是打开一个问题(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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在您的桌面项目上

添加一个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>
Run Code Online (Sandbox Code Playgroud)

运行你的游戏:

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);
            };
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在您的手机项目上

如上所述:

<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>
Run Code Online (Sandbox Code Playgroud)

最后:

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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

你完成了!