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.
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
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.
Time for my favorite part of Monday – Another article improving my TriangleShooter game! Last week, I promised you that I would spawn some more enemies, and that I would add in some other enemy types to make it more visually appealing. The great news is, both of those things are pretty easy. We’ll get started with the code base from last week, so you can grab that from my SkyDrive share.
We can start by adding in some additional enemy types. To begin with, we’ll drag and drop the rest of the Enemies from the Enemies file from SkyDrive into the Content project with the first enemy. We’ll then create some variables to hold the textures.
We’ll then load them from the content project in the LoadContent method.
We can try this out by changing the lines further down in LoadContent to make use of the new textures.
Next up, we need to start spawning some more enemies. What we’re looking to do here is to bring in new enemies every so often. The faster you spawn the enemies, the more difficult the game would be, so you can play with the amount of time between spawns. In order to track them, though, we’ll need a variable to track how long we have left until the next spawn. Since we’ve got some different enemy types, we may as well add in some randomization, so we’ll create a variable to handle randomness as well. As always, we’ll drop the variable up at the top of the game file.
And then we initialize them down in Initalize()
This sets up timeToSpawn as one second. We’ll count down until this reaches zero, then spawn another enemy. Luckily, there’s a easy way to get elapsed game time in the Update Method with the gameTime argument. We’ll subtract the elapsed game time from the timeToSpawn variable, then check to see if it is less than or equal to zero. If it is, we create a new enemy and add it to the enemies list. To add variety, we can pick a random edge, and spawn the enemy somewhere along it so that it doesn’t just always come from the same spot. Finally, we’ll reset the timeToSpawn so that we can spawn another. All of this will go in the Update method after we check the enemy collision.
There’s just so many of them!
Next week, we’ll add in shooting! Until this point, we were just a triangle moving around, but now we’ll finally be a triangle that shoots!