DCSIMG
Creating my first Windows Phone 7 game! - Guy Ronen's Blog

Guy Ronen's Blog

Lets talk about secs

Creating my first Windows Phone 7 game!

Back to mobile programming!!!

Years ago, I used to work for a small (yet great!) software company called Dooblo, where we developed apps for Pocket PCs using the .NET Compact Framework. That was fun and challenging!

Now, after I taught courses and published a book about developing 2D/3D computer games with Microsoft XNA for PC and Xbox 360, and when the Windows Phone 7 is almost ready (rumors say December 2010..), I decided it is wise to at least add to my book a chapter or two about developing games for the Windows Phone 7, which is yet (smartly enough by Microsoft) another platform for running XNA-based games (along with PC, Xbox 360 and Zune).

Games for the WP7 are developed using XNA 4.0 framework, which is a game development and runtime framework that extends the .NET Compact Framework, both installed on the device. The IDE is currently Microsoft Visual Studio 2010 Express for Windows Phone – CTP.

So, it’s time to create my first Windows Phone 7 game, using XNA 4.0!

I decided to blog about it, so i’ll have the important things, that I’ll encounter as I go, documented for myself and for the developers community :)

NOTE: This post is for developers which are familiar with basic XNA development concepts. Having said that, I think that even if you are not one, following my posts will make sense and should help you create your own XNA games for WP7.

So, here is what I have to tell you so far. The rest will be in the following posts.

  1. I tried to install the Windows Phone Developer Tools CTP - April Refresh.

    After the quite long installation process (30 minutes) ended, It showed an error regarding the installation of Silverlight 4.0. Whiile digging through the setup log I found this line:
    [20/06/10,12:34:56] Microsoft Silverlight 4.0: ***ERRORLOG EVENT*** : Error code 1502 for this component means "The event log file is full."
    As blogged in
    Aaron Stebner's WebLog, unfortunately, this error message is misleading, and it will not help to try to clear out your event logs in this scenario.

    The workaround (until a fix will be available in the next release of the CTP), is to uninstall Silverlight and then re-run the CTP installation (or even better, in case you read this post prior to your installation, just uninstall Silverlight before you run the CTP installation :)
    To uninstall Silverlight just go to ‘Programs and Features’ control panel, locate the item named ‘Microsoft Silverlight’, right-click it and select ‘uninstall’.
    image
  2. After a successful installation, I run the IDE (Microsoft Visual Studio 2010 Express for Windows Phone), and Created a new project of type Windows Phone Game (4.0).
    I got the initial project with the familiar Game1 class, almost similar to the one you get when you create a new Windows Game project in XNA 2.0/3.0 Game Studio. Hitting F5 starts the Windows Phone 7 emulator, and after a few seconds, I got the expected CornflowerBlue screen, which means that the game is running and all is good :)
  3. When I came to do the next step, which is obviously to render a nice
    “Hello WP7-XNA World” sprite on the screen, the first thing I noticed is that the Content folder (known to XNA developers since XNA 1.x) is gone, and instead we have a WindowsPhoneGame1Content project, which is referenced from the WindowsPhoneGame1 project’s Content References folder. This is a nice new approach to help us reuse built resourceimage assemblies between games.
    So, I dragged my HelloWorldMsg.png file –


    straight into the WindowsPhoneGame1Content project, added the basic necessary lines of code in order to draw this texture as a sprite using the good old Texture2D class, Content.Load<Texture2D> method and the spriteBatch, there I had it – My first “Hello WP7-XNA World” game!
     image
    [a real-size screenshot. The HelloWorldMsg.png image’s dimensions are 350 x 50]

The necessary code lines I added to the out-of-the-box Game1 class are:

  • // Declaring a class memeber to reference the sprite’s texture:
    Texture2D
    m_T2DHelloWorld; // (line 23)
  • // At the end of the LoadContent method:
    m_T2DHelloWorld = Content.Load<Texture2D>("HelloWorldMsg");
  • // At the end of the Draw method:
    spriteBatch.Begin();
    spriteBatch.Draw(m_T2DHelloWorld, new Vector2(60, 60),
                       Color.White);
    spriteBatch.End();

The next step will be to convert my Infrastructure XNA project (which contains basic infrastructure for XNA games, familiar to my students and the readers of my book), to become an XNA 4.0 project, and to use it to make the game actually do something (movements, collision detection, and of course -  retrieving user input...)

Comments

Ofer Heijmans said:

Hey Guy!

Great post, phone 7 is indeed a real change in ms approach to phones.. lets see how it goes.

Thanks for the first paragraph ;)

P.s - you can take credit for that some of your code now runs the surveys of a few global leading market research firms spanning 5 continents...

keep in touch.

# July 3, 2010 8:16 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: