How To: Create a Cross-Platform Game Solution
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 project for the Zune project that will contain low-resolution textures compatible with that device. We will also create content projects that are synchronized between the Windows project and the Xbox 360 project. These projects hold high-resolution textures that are compatible with both platforms, but are not part of the Zune project.
To create content projects 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" project has been added to all three projects.
Right-click the ZuneContent project in MyFirstGame, and then click Remove.
Right-click the ZuneContent project in Xbox 360 Copy of MyFirstGame, and then click Remove.
At this point, a "ZuneContent" project 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" project has been added to all three projects.
Right-click the NonZuneContent project in Zune Copy of MyFirstGame, and click Remove.
The solution now has "NonZuneContent" projects in the Windows and Xbox 360 projects, and a "ZuneContent" project in the Zune project.
To populate the platform-specific content projects
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" projects of both "MyFirstGame" and "Xbox 360 Copy of My First Game," and no longer in any of the projects' "Content" projects.
In Solution Explorer, in the Zune Copy of MyFirstGame project, right-click the ZuneContent project, 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" project (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.