Windows Phone Resources
I’ve been using the beta since then, and things are going great. I’ve posted some feedback to the Windows team through the links on all of the windows, but they’ve mostly been little things like the mismatching case in HomeGroups and homegroups. I worked tech support and wrote user manuals for a product I worked on in my first development job, so I get a little obsessed about those things. I have to fight not to highlight errors in tech books I read through.
Most applications have run without a problem. I did run into a problem with Skype, but it was actually just a popup that came up when I was running the install that told me that it wasn’t going to work, so I should download the latest beta. I did, and it worked fine. Another thing I ran in to was getting my phone connected to it. I have a Blackjack II that is really particular about how it charges off of USB, and unless it is recognized, it won’t take juice from the port. I plugged it in, and the driver tried to install, then failed. I looked around for some information on it, but couldn’t find any, so I just tried installing the Windows Mobile Device Center for Windows Vista x64, and it suddenly found my phone and everything worked great. The final thing I ran in to was a problem with Live Mesh. I use it a lot, so I couldn’t be without it on any machine. I even got it on my phone (They just expanded the CTP), but on Windows 7, Live Mesh didn’t play well with Aero. Turns out there was a fix for it ready, but it was being held off of until the holiday freeze on new installs was off. It should be available tonight. I’ll let you know how it works.
Update: The site with the process I followed for creating the USB drive installer is at http://kmwoley.com/blog/?p=345
Live Mesh has been working great with the new update, though I did have some problems remoting into my 7 desktop from my Mom’s place over the weekend, but I think it may have been in part because her internet barely qualifies as broadband.
As I was putting together some final materials for our upcoming series of DevCamps for Windows Phone, I noticed that the Windows Phone 7.1.1 Update is available as of today. The update allows developers to test on a new emulator running with 256 MB of RAM, and also lets you develop using the emulator under Windows 8. Of course, since Windows 8 is still in a pre-release form, it’s still not an officially supported scenario, but I am going to give it a try for sure.
You can read more about the release on the Windows Phone Developer Blog, and download the update from MSDN.
Last week, we added scoring, and keeping track of the high score over a set of games. The problem is, when you exit the game for any reason, you lose your high score. That’s because everything is unloaded from memory, so when you start your game over, it has nothing to start from. This week, we’ll save your high score to a file, so we can load it back up when you restart your game. To begin, we’ll load the code from last week over at the SkyDrive Share.
When working with files, we’ll need to add a few libraries. On the Windows Phone, applications have access to a special type of storage called IsolatedStorage, which is a file store that is accessible only by your application. Additionally, we will be storing our high score in an XML format, and accessing it with LINQ. To work with these, we’ll the following three include statements:
Once we’ve got these, we’ll just need to set up two simple methods. We simply need to save to the file, and load from the file. We’ll then just need to update the game to call the load method when it starts, and the save method at the end of each game.
At the beginning of the SaveToFile method, we choose a file name to save the game state. You then open the Isolated Storage and open a file stream into it. We use FileMode.Create because we just want to overwrite a file if it’s there, and make a new one if it isn’t. The StreamWriter lets us write directly into the file we created in Isolated Storage. We then create a basic XML file that contains the high score inside of a State element.
To load from the file, we use the same file name we defined when we saved our state. We then open the Isolated Storage using a StreamReader, and load its contents into a XDocument. This lets us use LINQ to pull in the elements that we saved. We walk through the elements named HighScore, and parse its contents into the highScore variable. The whole thing is wrapped in a try catch block because the file might not be there, or maybe there is something wrong with the file. We don’t want that to crash the game, so we just let it go.
Now we need to use these methods. First of all, we just need to load in the file in the Initalize method.
And finally, we need to save it. You could put it in every time the high score is beaten, but file I/O is expensive, so this could cause performance problems. Since we are really storing game high scores, why not drop it into the update method when the player dies.
And there you go, your high score is saved across application launches. Remember that if you restart the emulator, your isolated storage will be blown away, so you’ll lose your high score. This will also happen in you uninstall the game and then redeploy.
Next week, we’ll be adding sound effects, so stay tuned.
Download the latest version of the source code.
This week we’ll be starting a new game for the Windows Phone. We’ll be using Silverlight this time around, and building a language learning game. The idea behind the game is to make use of a database of words and meanings, pick a word, and give four possible definitions. I actually originally built the first version of this game in XNA, and when I redid it in Silverlight, the implementation ended up being much easier. This week, we’ll start with a new Silverlight project, and walk through what that gives you. We’ll also look at a source of graphics we’ll be using for the game.
To begin with, load up Visual Studio 2010 Express for Windows Phone, and choose File –> New Project, and under the Silverlight for Windows Phone templates, choose Windows Phone Application. In the Name field, type QuizGame, then click OK. You’ll get a new solution containing a single project with a few files. The basic structure a Silverlight application is a set of XAML files, containing markup that defines the user interface, and .cs files with code behind. In the MainPage.xaml file, you’ll get a visual desginer with a few elements in it. The layout is done through a Grid element containing a StackPanel with two TextBlocks. When you run the application, the emulator will pop up and display the application, looking something like the following:
The numbers on the right of the page is a frame rate counter. You can turn it on or off using the following line in the App.xaml.cs file’s constructor.
The other important files in the project are the ApplicationIcon.png file, the icon that will appear in the list of apps on the phone, Background.png, the image to display when your application is "pinned" to the Start screen, and SplashScreenImage.jpg, the splash screen that will be displayed when you launch the application.
We’ll be getting deeper into the XAML next week when we lay out the user interface. This week, we’ll finish off by looking at the source of images we’ll be using. There’s a great resource over at http://www.lostgarden.com/ where an artist occasionally posts sets of graphics like the one we will be using. The post in question is Danc's Miraculously Flexible Game Prototyping Tiles.
Here’s an example of the type of graphics we’ll be using.
See you next week, when we’ll set up the game interface.
You still have time to get your game into the You've Got Game Sweepstakes before the February 29th deadline. For every game you create and publish a to the Windows Phone Marketplace, you get another entry for a chance at winning a Dell Alienware M18x laptop or an Xbox LIVE Gold Card.
Head over to http://aka.ms/ygg to find out more about the contest, how to enter, and what you can win. Rules are at http://bit.ly/YGGRules