Flap Flap

Development Diary Converting XNA 3.1 to XNA 4.0

20-Mar-2011

I have finished applying the changes required to convert Flap from XNA 3.1 to XNA 4.0. The changes haven't been too arduous.

During the conversion I have used two key resources. Shawn Hargreaves excellent XNA blog. http://blogs.msdn.com/b/shawnhar and the Nexlon Studio cheat sheet. http://www.nelxon.com/blog/xna-3-1-to-xna-4-0-cheatsheet/

Maximum Texture Size 4096x4096

The biggest single issue for Flap was the maximum texture size limits. Many graphics cards have a maximum texture size of 4096x4096. This is now enforced in XNA. The thinking is really clear - try to remove as many issues for developers by saving them from themselves. Windows 7 Phone devices will really not support anything higher. I knew this when I first authored the scrolling level graphics. It was easier to author a very wide texture but I always knew that I should have split into sub rectangles off a 4096x4096 texture.

SpriteBlendMode is now BlendState

The enumeration for blend mode has been replaced with a set of static BlendState instances. My SpriteBatch.Begin calls were all pretty much in a common Actor class. As a result changing the call sites wasn't too bad.

I do find that graphically there are small differences between XNA 3.1 and XNA 4.0. A few tweaks to the textures used and similar changes and I'm happy with the final results.

TransparentWhite has been removed from Color

TransparentWhite and TransparentBlack have been replaced with a single Transparent. This obviously does make a different when you are doing linear extrapolations and similar functions.

This was a bit tricky as many of the call sites were actually in XML files parsed via the content loader and the XmlImmediateSerializer.

StorageContainer

The storage container mechanisms to actually create and read files has actually been changed quite a bit. The abstraction has moved to the container itself. Previously you would simply create a FileStream and use the StorageContainer Path to instantiate the files.

This is actually a change for the better. The abstraction is now where it should be. The different types of storage know how to create files and can pass a Stream type back from OpenFile. The XNA 4.0 compact framework on the Xbox has a specific extension assembly for XML serialization. That can throw you for a few minutes as you try to work out the missing reference!

Effect.CurrentTechnique.Passes[0].Begin is now Apply

The Effect framework has changed in a number of ways. The one that affects everybody is a new Apply method. Changing the call sites was easy due to the common base classes I use throughout the code. There are a few specialist types that have none trivial rendering that do there own thing.

The shield effect looked quite different under XNA 4.0. I think this is down to changes in the HLSL compiler and possibly pixel shaders that worked but didn't originally work as per the specification.