Run XNA games without code changes in Silverlight. Since the game compiles into straight Silverlight code, it will run anywhere that Silverlight can. Now with support for Silverlight 5 Toolkit's SpriteBatch and other XNA compatibility.
More here soon, including more samples and instructions on how to use this. Every time I try a new game, the library gets a little more complete so I'm sure there are some holes right now.
If you get your XNA game running in Silverlight, we'd love for you to submit it to Silver Arcade http://www.silverarcade.com
,our new game site for Silverlight games. Until we have a contact form on the site, you can contact me directly or here http://www.bluerosegames.com/brg/contact.aspx
Getting your game going:
1. Add all of your source files to your Silverlight application. You can add these "as link" if you want to share them with both XNA and Silverlight.
2. Replace Microsoft.Xna.Framework with SilverArcade.SilverSprite everywhere in your code. You can wrap these in a #if SILVERLIGHT if you want it to compile for both XNA and SilverSprite.
3. NEW: The Game class now inherits from Canvas, so you just need to add your Game class (by default this is Game1) to your XAML or in code. Here is an example from the snake game sample:
Width="400" Height="300" xmlns:game="clr-namespace:SnakeGame">
<Grid x:Name="LayoutRoot" Background="White">
4. Add content to your silverlight app:
Eventually I'd like to read the xnb files for everything if possible. For now, adding content is a bit messy.
Textures - Add the .xnb file built by the Windows XNA Debug project, only uncompressed xnb files right now. The texture itself can be compressed, in XNA this is a property you can set, and it can make the texture file 4 to 8 times smaller. Make sure the build action is set to "Content".
Sound - Add the audio file named the same as the asset name to the project, make sure the build action is set to "Content". Only mp3 and wma right now.
SpriteFont - NEW
There are two options for SpriteFont.
- a. Add the spritefont file to the project, setting build action to "Content". This will use Silverlight's built in text support. If you are using a font that is not one of the built in Silverlight fonts, add the ttf file to the project as a resource. You'll also need an extra line of code after creating your game class to map the XNA font name to the Silverlight FontFamily. It will look like this (taken from the snake game sample):
game.AddFont("Becker Black NF", "./Becker Black NF.ttf#Becker Black NF");
Some things just don't work at all, like XACT sound and networking. If you use a lot of different draw colors when drawing textures, a bitmap is created for each unique color (sorry it's the nature of the beast right now in Silverlight) and they're never cleaned up currently, so you can run into some major memory growth if you're not careful.
- b. Add the xnb file for the spritefont to the project, setting build action to "Content". This is required for bitmap fonts. Bitmap fonts won't perform quite as well, and you need to be careful if drawing a font with multiple random colors, because a bitmap is generated for each color.
A good amount of the code, especially things like Vector2 and math classes come from the Mono.Xna http://code.google.com/p/monoxna/