Zune HD Ins and Outs
/I’ve been preparing my TechEd sessions today. I’m doing two, one to Microsoft Student Partners (in a couple of hour or so) and one Interactive Session to the general conference. If you are here in Berlin please come along, I’d love to see you.
Since the session is about creating XNA games for the Zune HD not surprisingly I’ve been doing a bit of creating games for the Zune HD. I got my AlbumShaker running really nicely, and I thought I’d try running it on the original Zune players. I wasn’t expecting much, but I was really surprised to find that performance was quite acceptable, with the albums bouncing around the screen most satisfactorily. The program doesn’t seem to mind that it is running on one of the older devices, the game just gets “central” settings from the accelerometer. I even added some code to read the Zune pad, which emulates a gamepad thumbstick. This worked fine, except for a couple of issues.
Using the XNA Gamepad to Slow your Zune Game Down
The code for the album shaker makes a bunch of album sprite instances and then calls Draw and Update behaviours on every instance. The first version of my game called the GamePad.GetState method for each of the fifty or so albums on the screen. This did horrible things to performance. For some reason reading the Zunepad is very slow. I assumed that the pad would be read for a a given clock tick, and then that value cached for use in the game. This is not so. I got a huge performance improvement by reading the state once for all the albums and then picking up this value in each album.
Using the XNA Accelerometer to Make your Zune Game wobble
I was so pleased with my speedup on the original Zune I thought I’d do something similar with the accelerometer input, so I changed the game so that it read the accelerometer once and then cached that for use by all the items in that update. This had a really strange effect, where sometimes the items flickered madly about. I’m not sure why this happens, it is as if the GetRotation method on the AccelerometerState object actually corrupts the state in some way.
I only know that if you get a “fresh” reading for each item you want to input the game works fine. And this doesn’t seem to slow the game down either, which is nice.
So the moral of this is that it is fine to cache the gamepad settings (and in fact on the Zune this might make your game go faster) but the accelerometer values should not be cached..