This project is read-only.
ATTENTION: If the future of SilverSprite is important to you, please respond to the discussion here

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.

NEW! Silverlight 5 support. The Silverlight 5 Toolkit provides many of the XNA APIs such as SpriteBatch, Mesh and Model, and Input, but some classes are missing like Game and GameComponent. This makes much of the legacy SilverSprite code obsolete, but with Silverlight 5 the goal of SilverSprite is to fill in the gaps. The Silverlight 4 code has been preserved in case anyone needs it but there is a new source tree for Silverlight 5.

Getting your game going with SilverSprite for Silverlight 5
Step 1. Install Silverlight 5 Tools for Visual Studio 2010 SP1

Step 2. Install the Silverlight 5 Toolkit

Step 3. Create your Silverlight Project. You have 2 options here, and neither is ideal. You can use the Silverlight 3D Application template which creates a corresponding content project for you and adds the proper references to the Silverlight XNA libraries, or you can create a standard Silverlight project and add the other stuff yourself.

If you create a standard Silverlight project, you'll need to add the following assembly references:


Step 4. Add your content. If using the Silverlight 3D Application template you can add your content to the content project generated for you. Alternatively, you can edit the .csproj file and either replace the existing contentproj with your own, or in the case of a standard Silverlight Application you can add the XML for the content project.

  <XnaContentProject>..\Silverlight3dAppContent\Silverlight3dAppContent.contentproj</XnaContentProject> </PropertyGroup>
<Target Name="BeforeBuild">
  <MSBuild Projects="$(XnaContentProject)" Properties="XnaContentPipelineTargetPlatform=Windows;XnaContentPipelineTargetProfile=Reach" />
  <CreateItem Include="$(XnaContentProject)">
    <Output TaskParameter="Include" ItemName="XnaContentProjectItem" />
  <CreateProperty Value="%(XnaContentProjectItem.RelativeDir)">
    <Output TaskParameter="Value" PropertyName="XnaContentProjectPath" />
  <CreateItem Include="$(XnaContentProjectPath)cachefile*targetpath.txt">
    <Output TaskParameter="Include" ItemName="XnaContentCacheFile" />
  <ReadLinesFromFile File="@(XnaContentCacheFile)" Condition="Exists(@(XnaContentCacheFile))">
    <Output TaskParameter="Lines" ItemName="XnaContentOutputs" />
  <CreateItem Include="@(XnaContentOutputs->'$(XnaContentProjectPath)bin\AnyCPU\$(Configuration)\%(Identity)')" AdditionalMetadata="Link=Content\%(RelativeDir)%(Filename)%(Extension)">
    <Output TaskParameter="Include" ItemName="Content" />

Replace the XnaContentProject to point to the location of your content file. You can see examples of how this should look in the Samples folder.

Step 5. Add SilverSprite.dll to your Silverlight application.

Step 6. Add your source files to the Silverlight application.

Step 7. Add code to MainPage.xaml.cs to attach to your game class, here is an example from the Role Playing Game sample:

    public partial class MainPage : UserControl
        RolePlayingGame game;

        public MainPage()
            game = new RolePlayingGame();

Step 8. Unfortunately the Color enums such as Color.CornflowerBlue were not included with Silverlight 5, and there is no way to provide them, so SilverSprite provides a ColorHelper class. You can change Color.CornflowerBlue with ColorHelper.CornflowerBlue and the same goes for any other colors. To compile for both XNA and Silverlight, you can #if all of these or you can add ColorHelper.cs to your XNA project.

Some things just don't work at all, like XACT sound and networking.

A good amount of the code for the Silverlight 4 version and some for Silverlight 5 comes from the Mono.Xna library.

Last edited Sep 10, 2012 at 5:32 PM by billreiss, version 37