Lots of little improvements in XNA Game Studio 2.0

Originally posted to Shawn Hargreaves Blog on MSDN, Wednesday, November 21, 2007

Here are some changes that are too small to deserve their own post, but I think still cool enough to be worth mentioning...

The new GamePadState.IsButtonDown method is useful when writing generalized input helpers. This makes it easy to write a method that stores the previous and current gamepad states, then checks whether a specified button has been newly pressed.

The new Keyboard.GetState(PlayerIndex player) overload lets you read keyboard input for a specific player, which is important if you want to support the new Xbox chatpad accessory. The old overload without the parameter is the same thing as reading input for PlayerIndex.One.

Cue instances are no longer garbage collected while they are still playing. It is still more efficient to hang on to the Cue until it has finished, because we have to do some work in the finalizer to keep things alive if you leak them prematurely, but this is now just a minor optimization: your sounds will never cut out unexpectedly.

The GetEnumerator methods on ModelMeshCollection, ModelMeshPartCollection, ModelEffectCollection, and ModelBoneCollection now return Enumerator structs rather than IEnumerator interfaces. This means you can use foreach to iterate over the model data without generating garbage.

We fixed a bug that was causing SpriteBatch.DrawString to create garbage on Xbox. We also fixed a lower level bug that could sometimes cause any Dictionary<K,T> with value type keys to create garbage on Xbox. An interesting thing I learned while investigating this: if you run your program under the debugger, the JIT produces different code which sometimes causes boxing in places that would normally be ok. So make sure to run your program using ctrl+F5, rather than F5, any time you are investigating garbage collection issues!

We added kerning support to SpriteBatch.DrawString. This is optional, and enabled by a <UseKerning>true</UseKerning> element in the .spritefont XML file. Newly created .spritefont files have this enabled by default, but if you upgrade an existing project, you will get the old 1.0 character layout unless you explicitly add this element. You will probably want to change Spacing to 0 at the same time as you enable kerning.

Blog index   -   Back to my homepage