How To: Create a Cross-Platform Game Solution
Demonstrates how to create a cross-platform solution and manage game assets between platform projects.
This tutorial shows how create a solution with multiple synchronized projects where each project holds the same base source code, but the object generated from each is targeted to execute on a different XNA Game Studio-compatible platform. It also shows how to create game content projects within each platform project that hold non-synchronized or partially synchronized content specific to each platform.
The scope of the tutorial is limited to demonstrating how to use the synchronized project features of Visual Studio to manage a cross-platform solution. It does not demonstrate changes to the source code that would likely be needed in order to execute effectively on different platforms.
Creating a Cross-Platform Solution
To create a game solution with multiple projects for Windows, Xbox 360 and Zune
Follow the steps of Your First Game: Microsoft XNA Game Studio in 2D to create a Windows game for XNA Game Studio.
In Solution Explorer, select the MyFirstGame project.
From the Project menu, click Create Copy of MyFirstGame for Xbox 360.
When complete, a new version of the game project named "Xbox 360 Copy of MyFirstGame" will be added to your solution.
In Solution Explorer, select the MyFirstGame project once again.
From the Project menu, click Create Copy of MyFirstGame for Zune.
When complete, a new version of the game project named "Zune Copy of MyFirstGame" will be added to your solution.
Creating Platform-Specific Content
Because different devices have different characteristics, you may need to maintain different content that is specific to each platform. In the example below, we create a content folder for the Zune project that will contain low-resolution textures compatible with that device. We will also create content folders that are synchronized between the Windows project and the Xbox 360 project. These folders hold high-resolution textures that are compatible with both platforms, but are not part of the Zune project.
To create content folders exclusive to each platform project
In Solution Explorer, right-click the Zune Copy of MyFirstGame project, select Add, and then click New Content Project....
In the Add New Content Project dialog box, enter "ZuneContent" as the name for the new content project, and then click Add.
A new "ZuneContent" folder has been added to all three projects.
Right-click the ZuneContent folder in MyFirstGame, and then click Remove.
Right-click the ZuneContent folder in Xbox 360 Copy of MyFirstGame, and then click Remove.
At this point, a "ZuneContent" folder exists only in "Zune Copy of MyFirstGame." Any items added to this content project will be used exclusively by the Zune version of the game.
In Solution Explorer, right-click the MyFirstGame project, select Add, and then click New Content Project....
In the Add New Content Project dialog box, enter "NonZuneContent" as the name for the new content project, and then click Add.
A new "NonZuneContent" folder has been added to all three projects.
Right-click the NonZuneContent folder in Zune Copy of MyFirstGame, and click Remove.
The solution now has "NonZuneContent" folders in the Windows and Xbox 360 projects, and a "ZuneContent" folder in the Zune project.
To populate the platform-specific content folders
In Solution Explorer, in the MyFirstGame project, click and drag the bitmap asset (for example, mytexture.tga) from the Content project to the NonZuneContent project.
In the Content project, right-click the bitmap asset (mytexture.tga), and select Exclude From Project.
The bitmap asset should now be in the "NonZuneContent" project folders of both "MyFirstGame" and "Xbox 360 Copy of My First Game," and no longer in any of the projects' "Content" folders.
In Solution Explorer, in the Zune Copy of MyFirstGame project, right-click the ZuneContent project folder, select Add, and then click Existing Item.
In the Add Existing Item dialog box, select a bitmap file to add (for example, myZunetexture.tga).
This bitmap should be of appropriate resolution for the Zune device. You should now have the bitmap asset common to the Windows and Xbox 360 projects (mytexture.tga) in "NonZuneContent" and the bitmap asset for Zune (myZunetexture.tga) in "ZuneContent".
Right-click the newly-added file (myZunetexture.tga), and click Propertes.
In the Properties pane, change the AssetName property to match the same name as the AssetName property of the version in the "NonZuneContent" folder (for example, mytexture).
Setting this property to the same value will help the common source code to load the correct asset for the project's platform.