DCSIMG
June 2010 - Posts - Guy Ronen's Blog

Guy Ronen's Blog

Lets talk about secs

June 2010 - Posts

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

Finally! How to set the user’s data folder in a different drive in Vista/Windows 7, and re-use it after re-installing the OS

Have you ever wanted your C:\Users\YourUserName folder to reside in a different drive (other than the C: drive which you will need to re-format and re-install the OS occasionally..)?

Well, in Vista you can relocate the special sub-folders (i.e. Documents, Pictures, Videos, etc.). In Windows 7, we have the ‘Libraries’ features. But neither one of these OSs let you actually relocate the entire C:\Users folder or even on of the C:\Users\YourUserName folder to a different drive as a hole.

The need is obvious – You want to be able to easily re-install (or sometimes upgrade) your system drive, while keeping your data, which is not only documents, videos and pictures but also AppData (where the outlook.pst files reside for example), your Received Files folder and other data which is all under your user folder.

If only the C:\Users\YourUserName folder was D:\Users\YourUserName , life was much easier..

Well, after many hours of reading blogs and forums, I came across a few solutions for relocating the users folder, but no solution found for re-using the relocated user folders after re-installing the OS. Meaning – lets say I was able to relocate my user folder to D:\Users\MyUserName. The problem is that after I formated the system drive (c:) and re-installed the OS, re-creating a MyUserName account, than removing the created user folder and re-referencing the OS to the old D:\Users\MyUserName, the OS do not recognize this folder as a legitimate folder of the the newly created account. Either it loggs you off right after you try to login to your account or it creates a temporary account whenever you try to login.

Finally, I found a solution for that, so I figured it is worth blogging about.

I’ll summarize the list of steps you need to perform in order to relocate your user folder to a different drive, including the steps for re-referencing this folder after re-installing your OS!

Steps for Moving the C:\User\YourUser to D:\User\YourUser :

  1. Install the OS, and create your user. We’ll call it ‘YourUser’
  2. Create a temp user (with administrative privileges). We’ll call it ‘TempUser’
  3. Login with TempUser account
  4. Make sure you configured your windows explorer to list hidden and system files (Folder options)
  5. Move (cut/paste) the entire C:\User\YourUser folder to a different drive, for example to D:\User\YourUser .
  6. Create a HardLink from C:\User\YourUser to D:\User\YourUser , so when the OS looks for C:\User\YourUser it will find it in D:\User\YourUser . To create this hard link, open the cmd window with administrator privileges
    image and type:
    mklinkC:\User\YourUser” “D:\Users\YourUser” /j 
    (make sure there is no C:\Users\YourUser folder before you create the link, and that you run the cmd.exe as administrator)
  7. Restart the computer and login as YourUser, and there you have it. Your entire user folder is located in D: drive.
  8. Remove the tempUser account.

Steps for re-using your D:\User\YourUser folder, after re-installing the OS:

  1. Install the OS, and create your user. We’ll call it ‘YourUser’
  2. Create a temp user (with administrative privileges). We’ll call it ‘TempUser’
  3. Login with TempUser account
  4. Make sure you configured your windows explorer to list hidden and system files (Folder options)
  5. Browse to C:\User\YourUser (the newly created user folder), and copy all the hidden files which starts with ntuser* (should be 7 files
    image
  6. Paste these files to your old D:\User\YourUser (override the ones which resides there)
  7. Delete the C:\User\YourUser folder
  8. Create the hardlink as explained before.
  9. Configure YourUser to be the owner of the D:\User\YourUser folder:
    Right-Click ‘YourUse'r’ folder –> Properties –> Security –> Advanced –> Owner..
  10. Restart the computer and login as YourUser, and there you have it. Your entire user folder, located in D: drive, is now re-used.
  11. Remove the tempUser account.