Export (0) Print
Expand All

Creating a Cross-Platform Game Solution

This tutorial shows how to 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 nonsynchronized 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 Windows Phone

  1. In Solution Explorer, select the MyFirstGame project.
  2. On 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 is added to your solution.

    Dd282470.UsingXNA_CrossPlatform_HowTo_Xbox2(en-us,XNAGameStudio.41).png
  3. In Solution Explorer, select the MyFirstGame project once again.
  4. On the Project menu, click Create Copy of MyFirstGame for Windows Phone.

    Dd282470.note(en-us,XNAGameStudio.41).gifImportant

    The menu option to create a copy of a game project for Windows Phone is available only if Microsoft Windows Phone SDK is installed.

    When complete, a new version of the game project named Windows Phone Copy of MyFirstGame is added to your solution.

    Dd282470.UsingXNA_CrossPlatform_HowTo_Phone(en-us,XNAGameStudio.41).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 project for the Windows Phone project that will contain low-resolution textures compatible with that device. We will also create a content project that contains assets that are shared 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 Windows Phone project.

To create content projects exclusive to each platform project

  1. In Solution Explorer, right-click the top-level Solution node, select Add, and then click New Project.
  2. In the Add New Project dialog box, select Empty Content Project (4.0), enter PhoneContent as the name for the new content project, and then click OK.

    A new PhoneContent project is added to the solution's root node.

    Dd282470.UsingXNA_CrossPlatform_HowTo_Content1(en-us,XNAGameStudio.41).png
  3. In Solution Explorer, right-click the top-level Solution node, select Add, and then click New Project.
  4. In the Add New Project dialog box, select Empty Content Project (4.0), enter NonPhoneContent as the name for the new content project, and then click OK.

    A new NonPhoneContent project is added to the solution's root node.

    Dd282470.UsingXNA_CrossPlatform_HowTo_Content2(en-us,XNAGameStudio.41).png
  5. The solution now has a NonPhoneContent project that will hold assets for the Windows and Xbox 360 projects, and a PhoneContent project that will hold assets for the Windows Phone project.

To connect platform-specific content projects with their game projects

  1. In Solution Explorer, right-click the Windows Phone Copy of MyFirstGame project, and then click Add Content Reference.
  2. In the Add Content Reference dialog box, select PhoneContent, and then click OK.

    The Windows Phone game project now refers to the PhoneContent project for its game assets.

    Dd282470.UsingXNA_CrossPlatform_HowTo_Content3(en-us,XNAGameStudio.41).png
  3. In Solution Explorer, right-click the MyFirstGame project and then click Add Content Reference.
  4. In the Add Content Reference dialog, select NonPhoneContent, and then click OK.

  5. In Solution Explorer, right-click the Xbox 360 Copy of MyFirstGame project and then click Add Content Reference.
  6. In the Add Content Reference dialog box, select NonPhoneContent, and then click OK.

    Both the Windows and Xbox 360 game projects now commonly refer to the NonPhoneContent project for its game assets.

    Dd282470.UsingXNA_CrossPlatform_HowTo_Content4(en-us,XNAGameStudio.41).png

To populate platform-specific content projects

  1. In Solution Explorer, click and drag the bitmap asset (for example, mytexture.tga) from the Content project to the NonPhoneContent project.

  2. In the MyFirstGameContent project, right-click the bitmap asset (mytexture.tga), and select Exclude From Project.

    The bitmap asset should now be in the NonPhoneContent project referenced by both MyFirstGame and Xbox 360 Copy of My First Game, and no longer in the MyFirstGameContent project.

  3. In Solution Explorer, right-click the PhoneContent project, select Add, and then click Existing Item.

  4. In the Add Existing Item dialog box, select a bitmap file to add (for example, myPhonetexture.tga).

    This bitmap should be of appropriate resolution for the Windows Phone device. You should now have the bitmap asset (mytexture.tga) common to the Windows and Xbox 360 projects in NonPhoneContent and the bitmap asset (myPhonetexture.tga) for Windows Phone in PhoneContent.

    Dd282470.UsingXNA_CrossPlatform_HowTo_Content5(en-us,XNAGameStudio.41).png
  5. Right-click the newly-added file (myPhonetexture.tga), and click Properties.

  6. In the Properties pane, rename the AssetName property to match the same property (for example, mytexture) in the NonPhoneContent project .

    Setting this property to the same value helps the common source code to load the correct asset for the project's platform.

Community Additions

ADD
Show:
© 2014 Microsoft