我尝试使用SharpDx为Windows和Windows Phone 8.1编写游戏。但是当我尝试将Windows Phone 8.1版本添加到我已经存在的Windows 8.1游戏时,我收到一些错误并且应用程序不起作用。现在的问题是:对于Windows通用应用程序,是否存在XNA样式的SharpDx模板,例如我为我唯一的Windows 8.1游戏(来自SharpDx Visual Studio扩展)获得的模板?
答案 0 :(得分: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);
}
}
}
在桌面项目上
添加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);
}
}
}
你已经完成了!