Export (0) Print
Expand All

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

  1. Follow the steps of Your First Game: Microsoft XNA Game Studio in 2D to create a Windows game for XNA Game Studio.
  2. In Solution Explorer, select the MyFirstGame project.
  3. 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.

    Dd282470.UsingXNA_CrossPlatform_HowTo_Xbox2(en-US,XNAGameStudio.30).png
  4. In Solution Explorer, select the MyFirstGame project once again.
  5. 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.

    Dd282470.UsingXNA_CrossPlatform_HowTo_Zune2(en-US,XNAGameStudio.30).png

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

  1. In Solution Explorer, right-click the Zune Copy of MyFirstGame project, select Add, and then click New Content Project....
  2. 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.

    Dd282470.UsingXNA_CrossPlatform_HowTo_Content1(en-US,XNAGameStudio.30).png
  3. Right-click the ZuneContent folder in MyFirstGame, and then click Remove.

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

  5. In Solution Explorer, right-click the MyFirstGame project, select Add, and then click New Content Project....
  6. 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.

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

    Dd282470.UsingXNA_CrossPlatform_HowTo_Content2(en-US,XNAGameStudio.30).png

To populate the platform-specific content folders

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

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

  3. In Solution Explorer, in the Zune Copy of MyFirstGame project, right-click the ZuneContent project folder, select Add, and then click Existing Item.

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

    Dd282470.UsingXNA_CrossPlatform_HowTo_Content3(en-US,XNAGameStudio.30).png
  5. Right-click the newly-added file (myZunetexture.tga), and click Propertes.

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

Community Additions

ADD
Show:
© 2014 Microsoft