Home > Blog > Silverlight and XNA Framework Game Development and Compatibility

Silverlight and XNA Framework Game Development and Compatibility

The session I presented at MIX ‘10 touched on the compatibility between Silverlight for Windows Phone and the XNA Framework. We have a lot of integration in this release which means that most of the API set of the XNA Framework can be used from a Silverlight application. More will follow on those specifics soon!

For this release, applications cannot mix the use of Silverlight UIElements with the use of the XNA Framework GraphicsDevice. I know this is a hard choice for me, since I’d love to be able to leverage a great Silverlight interface from my XNA Framework Game, but you’ll want to choose what technology works best for your scenario.

We have different Application Models between Silverlight and the XNA Framework that provides some choice of how you approach development:

  • Silverlight is a modern event driven application and UI framework, this is very much what you see with most .NET technologies today.
  • XNA uses an Update/Draw/Present frame loop that’s designed around game development and high performance graphical applications.

Does this mean you can’t or shouldn’t program games in Silverlight? Absolutely not! In fact there are already great examples of games built in Silverlight today!

Choosing one or the other really depends on the features of the platform you intend to use and how you approach game development, but it’s not always a clear path. With that here are some of the reasons you *might* choose one framework over another and the differences between the application models.

Platform Features

Windows Phone Application
(Silverlight-based application model)

Windows Phone Game
(XNA Framework Application model)

Application programming model

Event-driven application model.  Great for heavily UI based games.

Traditional frame loop for more simulation based content.

Control-based, data-bound UI development

UIElement and related types

None, the developer must write their own.

Video playback

Rich video integration via MediaElement

Fullscreen playback via the system media player

2D graphics

Rich paths, shapes, and brushes, etc…

High performance 2D rendering for large amounts of sprites.

3D graphics

Perspective effects using PlaneProjection transform.

Provides Hardware Accelerated 3D API’s.

Primary data serialization model

XAML

Content Manager

Designer tooling

Expression Blend, VS XAML designer.

XNA Content Pipeline integrates 3rd party tools for creating 3D model & texture assets for your application.

Device sensors

Same API in either programming model

 

Access to user’s songs and pictures

Same API in either programming model

 

There’s no perfect “one size fits all” answer to help you make the choice for what is best for your game, so you’ll want to think about the tools you want to use, and the type of experience you want to enable when approaching developing your game.

Got questions? Leave a comment and we’ll be happy to help!


-Michael

  • Share/Bookmark
Categories: Blog Tags:
  1. March 26th, 2010 at 14:09 | #1

    Hi MIchael,

    What about battery life? Based on Seema's presentation at MIX I'd think that the exact same game implemented in XNA would take up more resources than if it was written in Silverlight. Something about Silverlight only repainting if it needs to, versus XNA always repainting the screen.

    I'd like to think those optimizations are available for both Silverlight and XNA, but wanted to double check. If I'm completely off, please let me know. Thanks!

  2. March 26th, 2010 at 14:37 | #3

    Hello Michael,

    I am interested to hear the answer to Kelly's question. Developing games for the Windows Phone is very sounds intruiguing to me, but I would like to know the pros and cons of using either Silverlight or XNA. Being a Silverlight developer, I know I can build a game, but XNA is literally built for the task.

    Any thoughts on what each one of the technologies brings to the table?

    Thank you!

  3. March 26th, 2010 at 15:45 | #4

    "For this release, applications cannot mix the use of Silverlight UIElements with the use of the XNA Framework GraphicsDevice."

    What about rendering a XNA surface to WPF's D3DImage? What if I want to create a level editor without (cumbersome) workarounds?

  4. March 26th, 2010 at 23:58 | #5

    Well, you certainly won't be making a level editor on the windows phone, so there's not really a need to be concerned there ;-) On windows you can always launch other forms (wpf or winforms) from an xna-based level editor. As both the xna form and the launched form are in the same process, they can talk to each other. So you can have a wpf-based form controlling the rendering on a separate xna form. If you absolutely *must* have them in the same form (and I challenge whether that's actually truly nescessary), you can relatively easily render onto a custom winforms form:
    http://creators.xna.com/en-US/sample/winforms_ser...

    • March 30th, 2010 at 18:10 | #6

      Joel, I know how to do workarounds: http://www.codeproject.com/KB/game/XNA_And_Beyond...

      Even if you can have them organized the way you say, with WPF you will experience airspace issues and thus, you won't be able to render, say, a Wpf-contextual menu on top of the XNA "panel".

      There are a couple of workarounds using D3DImage and the old MDX Gfx API, but to me that is not a business-wise option.

      The thing is that I want them coexisting in the same "form" (a Wpf-based one) since I want to be able to use Wpf controls on top of (not inside ) the panel where the XNA surface is presented. It's quite restrictive not to have that option out form the box itself.

      If it weren't for sandboxing I'd be happier than ever if I could mix an XNA-app with Silverlight controls on Windows with no airspace at all, to create a level editor.

  5. March 28th, 2010 at 22:54 | #7

    It is great to hear that Silverlight and XNA are actually converging, even if there are still some ways to go. I've been thinking recently how great it would be to have Blend support for XNA games. (Imagine if Blend had an XNA target and included niceties like Title Safe Area snaps and borders.)

    Possibly extra ammunition in the case for Blend support for XNA (and maybe even unmanaged games): have you noticed ScaleForm yet? It's an increasingly common games middleware system, used by some of MGS' own games even, that imports Flash files for game UIs. It seems like a great product, but, again, imagine if Blend could provide a first class design experience for Game UIs and the already reusable bits of XAML/Silverlight were the middleware?

  6. May 24th, 2010 at 13:00 | #8

    Hi is there any way to mix XNA and Silverlight ? I mean, is there a way to build a DCOM+ object using XNA and use this object directly from a Silverlight application ?
    Thank you very much !

  1. No trackbacks yet.