Project Description
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.

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:
New for 1.0 Beta: support for SpriteEffects, all draw methods are now supported, improvements in sound, layerDepth is honored, DrawOrder for DrawableGameComponents is implemented, rotation of text supported, can add PNG and JPG texture files directly for textures, bug fixes, other improvements.

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. 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:

Eventually I'd like to read the xnb files for everything if possible. For now, adding content is a bit messy.

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 or JPG file using a file name that matches the asset name, making sure the build action is "Content". This can be more size efficient, faster, and smaller in memory, but you cannot "tint" the drawing by specifying a drawing color. The Alpha value of the drawing color will still be honored.

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. 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.

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.

Last edited Apr 30, 2009 at 11:14 AM by billreiss, version 27