Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

c# - Is there a SharpDx Template, for a Windows Universal App?

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)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

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 !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...