gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:55:21 25 4
gpt4 key购买 nike

我尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com