Migrating from Zune to Windows Phone
Games that were written for Zune and Zune HD in previous versions are natural candidates for porting to Windows Phone. Windows Phone shares many common attributes with the Zune HD: a handheld form-factor, small screen, and the primary game inputs are multitouch and the accelerometer.
Since the Zune and Zune HD are only supported in XNA Game Studio versions including and prior to 3.1, and Windows Phone is a new platform as of version , there is no direct way to update applications written for Zune to Windows Phone.
This topic describes how to port a Zune application from XNA Game Studio 3.1 to Windows Phone with XNA Game Studio 4.0.
Creating a new Windows Phone Project
The first thing to do is to create a new Windows Phone project. If you don't already know how to do this, see Creating a Windows Phone Game or Library Project.
Migrating Your Content
Copy your content from the Zune project's Content folder to the content project folder for your new XNA Game Studio 4.0 application. This will be named, by default, ProjectNameContent inside your solution folder. Unlike content projects in XNA Game Studio 3.1, content projects in XNA Game Studio 4.0 are not nested within the game project, but are separate projects in the same solution.
To add the content to your content project
- Right-click the content project.
- Choose Add, then Existing Item.
- Choose your content (you can select multiple files at once), and click Add.
|Asset names, as with XNA Game Studio 3.1, are named according to the filename. If you need to, edit the Asset Name field in each content's Properties pane so that it matches the asset name in your game code.|
Migrating Your Code
The next step involves moving your old sourcefiles to your new XNA Game Studio 4.0 project.
To migrate your code
Copy the source files from your old application into the new application's project folder, located inside the new application's solution folder. Both of these folders will be named with the project name chosen for your application.
If you renamed either Game1.cs or Program.cs in your old project, remove these files from your new project.
If you have additional files beyond Game1.cs and Program.cs (or renamed these in your old project), add these to your project by right-clicking the project name in Solution Explorer, selecting Add, then Existing Item.
Updating Your Code
Once you've copied over your old source-files, you'll need to update your code for XNA Game Studio 4.0 and Windows Phone. What you do here depends on what features you used in your old project, so this section will provide information specific to common feature areas used with Zune and Zune HD games.
The screen size of a Windows Phone 7 device is, at minimum, 800x480. If your application expects a screen-size of 480x272 (Zune HD) or 240x320 (previous Zune models), you will need to adjust your application accordingly. This can be done either by resizing your art assets to take advantage of the higher resolution available on Windows Phone 7, or by taking advantage of the built-in hardware scaling.
For many applications, using the built-in hardware scaling has several advantages:
- There is no need to convert any of your existing textures to fit the new screen resolution.
- There is no need to convert screen coordinates for touch input .
To use built-in hardware scaling, simply set the preferred back buffer width and height to match those of the Zune device you're porting from. For example:
Although Windows Phone 7 devices have hardware buttons, these cannot be used by games on Windows Phone. You will need to manually rewrite code that uses hardware buttons to use the input devices available on Windows Phone: touch input or accelerometer input.
Multitouch input has moved to its own assembly: Microsoft.Xna.Framework.Input.Touch.dll. If this was not added to your project by default, you'll need to add it yourself to access the XNA Game Studio touch input classes and methods.
Make sure that you also have using Microsoft.Xna.Framework.Input.Touch statements in any source files that will be using its classes.
For more information about using touch input, see Working with Touch Input (Windows Phone).
Accelerometer input is now handled by the Microsoft Windows Phone Developer Tools, which requires adding the Microsoft.Devices.Sensors assembly to your project and adding associated using statements in the sourcefiles in which you'll be using its classes and methods.
Accelerometer input, like many Microsoft Windows Phone Developer Tools features, is event-driven, and you'll need to create an event handler to that will be called when accelerometer events are received by the game.
For more information about using accelerometer input, see Retrieving Accelerometer Input (Windows Phone).
StorageContainer.TitleLocation has been deprecated in XNA Game Studio 4.0, and no longer exists—in fact, the entire Microsoft.Xna.Framework.Storage namespace doesn't exist for Windows Phone projects. To access title storage on Windows Phone, use OpenStream to get a filestream to the storage location.
Writeable user storage on Windows Phone is not provided by XNA Game Studio. To write data to the device to save game state or player progress, you can use IsolatedStorageFile.GetUserStoreForApplication to get an IsolatedStorageFile object that can be used to create files and directories, or to read from or write to existing files. For more infomation, see Writing Data (Windows Phone).