Project DescriptionRun 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.
SilverSprite is brought to you by Silver Arcade
http://www.silverarcade.com, an ad based game site for Silverlight games. Please consider hosting your game with Silver Arcade once you get it working. If your game is also on Xbox Live Community Games, we will feature that prominently and provide a link to the Xbox Live Marketplace page for your game.
Watch the Channel 9 video on SilverSprite here:
http://channel9.msdn.com/shows/Continuum/SilverSprite/See SilverSprite in action:
Getting your game going1. 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.2. Add references to SilverArcade.SilverSprite.dll and SilverArcade.SilverSprite.Core.ll to your project.
3. Add your Game class (by default this is Game1) to your XAML or in code. Here is an example from the snake game sample (remember the xmlns definition) :
<UserControl x:Class="SnakeGameSilverSprite.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300" xmlns:game="clr-namespace:SnakeGame">
<Grid x:Name="LayoutRoot" Background="White">
<Canvas>
<game:Game1 x:Name="game"/>
</Canvas>
</Grid>
</UserControl>
4. Add content to your silverlight app:
Textures -
- Option 1: 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".
- Option 2: Add the PNG, JPG or BMP file using a file name that matches the asset name, making sure the build action is "Content". This can make for a smaller XAP file.
Sound - Add the audio file (
not the xnb 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 - There are two options for SpriteFont.
- Option 1: 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");
-OR-
- Option 2: 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.
Some things just don't work at all, like XACT sound and networking.A good amount of the code, especially things like Vector2 and math classes come from the Mono.Xna
http://code.google.com/p/monoxna/ library.