Intermission #4 – Moving to Windows Phone

No need to guess what this little section is about.  Games on Windows Phone 7.

For now this is going to be a side project to the main tutorial since XNA 4.0 and the Windows Phone 7 kit hasn’t been fully released yet.  So on with the show.

Source updated for Final combined update project for GS 4.0 project here on Codeplex (Windows and WP7)


Getting started

 

For the Windows Phone side of this tutorial you are going to need the Windows Phone Development Kit (The April refresh is the latest), this will download and install everything you need including:

  • Visual Studio 2010 Express for Windows Phone
  • XNA Studio 4.0
  • Windows Phone 7 Emulator
  • Silverlight for Windows Phone 7

Get them installed and started and you see the great new Visual studio 2010 interface now completely re-written in WPF.

VS2010ExpressPhone

 


 

New project

Now exactly the same as before in this earlier post, you need to set up a new project, except this time you need to browse to the XNA Game Studio 4.0 section and select the “Windows Phone Game (4.0)” project.

NewPhoneProject

 

I suggest calling the project “XNAStarTrooper2D_Phone7”, select an appropriate folder and click OK, then you will be presented with a nice clean empty Phone solution.

First thing you should notice is that in a new phone solution the content and code projects are already split up for you, bear this in mind for the next step.

image

Now copy over the Engine Folder from your current Startrooper game to the code project and then copy over the class files beginning with StarTrooper (StarTrooperGame, StarTrooperSprites and StarTrooperBackground).

Finally copy over the Pictures, Music and Sounds folders from the content project in the original project and paste them into the Content Project of the Phone Game (making sure to select the content project and not the code project!!)

You should now have a solution made up like the following:

image


Updates for Windows Phone 7

Now straight off the bat, if you build the project there will be several errors logged, fear no though as this is to be expected.

Now with any upgrade project, I’ve always found it easier to do the conversion myself as you can ensure you know exactly what changes are required, to that first we need to update the default “Game1.cs” class with our engine and setup code from the StarTrooperGame.CS

 

This is broken down into the following steps:

  1. Copy the InternalUpdate and LoadResources functions to the end of the Game1.cs
  2. Copy the base attributes
  3. Copy the constructor updates
  4. Apply the update from the previous post for the graphics buffer.
  5. Finally copy the additional code from the update and draw functions

What you should end up with is the following.

 

You may note that I’ve left the Graphics backbuffer values to the default for windows phones, this is better to leave this for now since the phone project is separate.

Last job to ensure the project is cleaned up and tidy.  Delete the original “StarTrooperGame.cs” file and then Rename “Game1.cs” to “StarTrooperGame.cs”.

This will keep the main tutorial and the Windows Phone project in line with code changes.

 


 

Final Changes

If you compile the project now you will notice that there are still errors, this is down to the “ICloneable” interface not being available for Windows Phone Projects, not to fear though as the project can live without it (The ICloneable interface just gives a standard implementation for Cloning objects)

SO we need to update the Sprite and Animation classes and remove their iCloneable interface references, from:

To:

 


And that’s it, if you run the project you should now see the game running happily in the Windows Phone Emulator.

 

image

Final code for this intermission can be found here.

Source updated for Final combined update project for GS 4.0 project here on Codeplex (Windows and WP7)

Laters, next on to Lesson 5 – Transformation and Collision of Sprites
%d bloggers like this: