How can I port my Windows Phone game to a Silverlight thing that I can use on a webpage?

142 views Asked by At

I'm confused about how to port my WP7 C# game to the web using Silverlight.

I know that code written in C# using the Windows Phone (add-in? plugin? other?) for Visual Studio makes a Silverlight app. But how can I embed my finished WP7 app in a webpage?

I've seen some things such as ExEn, SilverSprite, and XnaTouch {the page redirects to MonoGame}, but I'm confused if I even need something like this in order to make my game playable on the web. I've got a feeling the capability may even be embedded in Visual Studio. Is it even possible to do this without rewriting all the code?

Shortened version: How can I port my WP7 C# game to the web using Silverlight?

3

There are 3 answers

0
Nicholas W On BEST ANSWER

Create a new project in Visual Studio targeting Silverlight beside your WP7 project. Then if your existing code is structured nicely, you should be able to re-use most of your "back-end" code (the views, viewmodels people talk of). The best way to do this for files that are common is to add them as links to the new project, so you don't have to keep them both up to date - if there are small changes between versions you can use conditional compilation to do this.

You'll want to use some completely new classes for some things, such as probably the top level view. Some XAML (eg a UserControl definition) might be usable between both with changes, though some people will favour always creating different versions. Have a look at this extensive article on cross-platform SL/WPF/WP7 development.

2
Kirk Broadhurst On

What have you tried?

If you create a Silverlight application in Visual Studio, you should be able to include all your existing Views, ViewModels, resources and so on. I don't know if you'll be able to make a single project that both builds into a WP7 and a Silverlight application but I personally wouldn't bother trying.

2
Ivan Zivkovic On

You can't directly - there are missing runtime components and features that are only available to Windows Phone applications.

You can, however, reuse lots of code, especially C# - all XAML code, I beleive, you'll have to copy/paste from WP7 XAML to Silverlight XAML.