I tried to write a game for Windows and Windows Phone 8.1, with SharpDx. But when I try, to add a Windows Phone 8.1 Version to my already existing Windows 8.1 Game, I get a few errors and the App doesn't work. Now the question: Is there an SharpDx Template in XNA Style for a Windows Universal App, like the Template I got for my only Windows 8.1 Game (from the SharpDx Visual Studio Extension)?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
No there isn't, yet.
What you should do is open an issue (https://github.com/sharpdx/SharpDX/issues) and ask for the feature to be implemented.
But you can still get started while waiting for it to be implemented :D
Here's how I tried your scenario:
- create a Universal App project
- add the SharpDX.Toolkit.Game NuGet package to each of your device project (howto)
Then on your shared project
Add your game:
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);
}
}
}
On your desktop project
Add a 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 your game:
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);
};
}
}
}
On your phone project
Do the same as above:
<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>
And finally:
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);
}
}
}
You are done !