What is SilverBullet?
SilverBullet is a Framework written on top of Microsoft SilverLight to allow hobbyists and developers to easily port XNA Games to SilverLight, allowing them to be run inside a web browser.
As SilverLight does not fully support 3D graphics yet, only XNA games that use the SpriteBatch can be succesfully run in SilverLight.
As SilverLight is developed further, we will add on this Framework, and eventually, hopefully, we will be able to equal the full XNA Framework in terms of functionality.
How to Port an XNA game?
Porting an XNA game--as long as it uses the SpriteBatch for Drawing--is rather easy;
Just add all (non-compiled) game content and classes to a new SilverLight Application project and add a reference to SilverBullet.dll.
Audio should be either in WMA, MP3, or WAV format. XACT is not supported.
Then, open the MainPage.xaml file and change the class name to the name of your game class.
Click the green (debug) arrow and behold your XNA game running in your webbrowser!
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, WMA, and WAV are supported at the moment.
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");
- 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.
Codebase
The SilverBullet codebase consist mainly of code snippets from the MonoXNA project, and the SlimDX project.
Both are open-source implementations of the XNA Framework, though SlimDX is a C++ based library and code had to be converted to C#.