我尝试使用SharpDx编写适用于Windows和Windows Phone 8.1的游戏。但是当我尝试将Windows Phone 8.1版本添加到已经存在的Windows 8.1游戏中时,出现了一些错误,应用程序无法正常工作。现在的问题是:是否有一个类似于XNA风格的SharpDx模板可用于Windows通用应用程序,就像我从SharpDx Visual Studio扩展中获得的仅适用于Windows 8.1的模板一样?
我尝试使用SharpDx编写适用于Windows和Windows Phone 8.1的游戏。但是当我尝试将Windows Phone 8.1版本添加到已经存在的Windows 8.1游戏中时,出现了一些错误,应用程序无法正常工作。现在的问题是:是否有一个类似于XNA风格的SharpDx模板可用于Windows通用应用程序,就像我从SharpDx Visual Studio扩展中获得的仅适用于Windows 8.1的模板一样?
目前还没有。
您应该打开一个问题(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);
}
}
}
<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);
}
}
}