Chapter 1. What’s New in XNA 4.0?
In this chapter, I review major changes that have been made in XNA 4.0. If you’re familiar with XNA 3.x or other versions, this is a great place to get started in this book. If you’re new to XNA, you should probably skip ahead to the next chapter. You won’t be missing out on anything, as all of the information covered in this chapter will be covered throughout the rest of the book.
Revised Project Folder Structure
The first thing you might notice when creating a game project in XNA 4.0 is that the structure of the solution has changed. In previous versions of XNA, the content pipeline picked up game content from a subfolder named Content, which was located within the game project you created, as seen in Solution Explorer (see Figure 1-1).
In XNA 4.0, the Content folder has been moved to a new project within your solution. The content project will be listed under the name GameProjectNameContent (with the name of your project replacing “GameProjectName”) and will be followed with the word “Content” in parentheses (see Figure 1-2).
You’ll add all your game content (audio, textures, models, etc.) to the content project in the same way you added them to the content folder in XNA 3.x. You will also still use the same code to access the content from the content pipeline, just as you did in XNA 3.x. This move makes working with multiple versions of the same project (e.g., if you built a project for both Windows and Xbox 360) much more user friendly and less confusing.
Develop Games for Windows Phone 7 Series
Just as in previous versions of the XNA Framework, XNA 4.0 is designed for cross-platform development. Developers using XNA 4.0 can write games for Windows, Xbox 360, and now Windows Phone 7 Series. Not only that, but aside from some resource management and screen resolution issues, nearly 100% of the code written for any of those platforms will also work on the other platforms. This gives game developers incredible flexibility to easily create games for each platform.
To learn more about developing games for Windows Phone 7 Series, see Chapter 17.
Graphics Profiles
Between today’s top-of-the-line graphics cards, which support DirectX 10 and higher, the powerful Xbox 360, and the introduction of Windows Phone 7 Series, the XNA Framework supports development on a wide range of devices with different hardware capabilities. In previous versions of XNA, these hardware differences had to be dealt with at runtime, which often led to platform-dependent code. To help facilitate development on these different devices, XNA 4.0 introduces the concept of profiles. These profiles allow developers to target certain hardware devices by supporting a specific set of graphics API designated by the profile they choose.
There are two profiles in XNA 4.0: Reach and HiDef. HiDef is designed for high-powered, top-of-the-line hardware, whereas Reach is designed to support a wider range of hardware devices. The Reach profile offers a limited set of graphic features and is a subset of the HiDef profile. When choosing to write a game using the Reach profile, you sacrifice some of the more powerful graphics API, but you’ll be assured that your game will work on a variety of devices (specifically Windows, Xbox 360 and Windows Phone), assuming those devices meet the minimum specifications for XNA 4.0.
The HiDef profile is designed to support today’s most powerful graphic devices. You can use the HiDef profile to target Xbox 360 hardware as well as Windows-based computers with graphics cards supporting at least DirectX 10.
You can identify which profile is supported by your hardware at
runtime by using the GraphicsAdapter.IsProfileSupported
method. A chart illustrating more detail on the differences
between the Reach and HiDef profiles is shown in Table 1-1.
Configurable Effects
In previous versions of XNA, the
BasicEffect
class was a very basic effect, implemented mainly to allow new
game developers to build games without in-depth knowledge of complex
shader code. The idea was that serious game developers would implement
their own shaders and not rely on the BasicEffect
class.
Much of that thinking had to change with the onset of Windows Phone 7, which does not support custom shaders. As a result, new configurable effects were added, available on both the Reach and HiDef profiles. These are:
- Basic Effects
The
BasicEffect
class has been tweaked to include more pixel and vertex shaders to support more realistic lighting and fog effects.- Dual Texture Effects
This effect allows you to use two different textures with independent texture coordinates. The two textures will be blended together for added complexity and detail.
- Alpha Test Effects
This effect uses a reference alpha and an alpha function to implement alpha testing. This can improve performance by updating only those pixels that are drawn in the scene.
- Skinned Effects
This effect uses bones and weights to determine the vertex positions. The effect is powerful when used for animation and instancing.
- Environment Map Effect
This effect uses textures and a cube map texture to shade objects based on the environment, reflecting the light from objects in the scene.
Built-in State Objects
Some of the state properties that were used in previous versions of XNA to modify the way scenes were drawn on the screen and the way the graphics device processes data sent to it by your game have been moved into state object classes. These classes are:
Scalars and Orientation
Scalars in XNA 4.0 allow developers to write their games without worrying about the native resolution or screen orientation. The scalars will automatically scale your desired resolution to the resolution supported by the device on which you’re playing your game. This enhancement dramatically improves game performance.
Screen orientation is most important on Windows Phone 7 devices, which switch rotation from varieties of landscape to portrait and back when the device rotates. The scalars automatically map your game from one orientation to another, and rotate input such as touch panel input accordingly.
Revised Input API
The Microsoft.Xna.Framework.Input.Touch
namespace contains classes that enable access to multitouch input on
Windows and Windows Phone devices. The namespace adds the
TouchPanel
class and TouchLocation
class, which enable access to touch points from input devices
(such as the touch panel in Windows Phone 7 series devices).
Additional Audio API
Two new classes within the
Microsoft.Xna.Framework.Audio
namespace have been added to improve audio support:
Music and Picture Enumeration and Video Playback
New audio support has been added to allow developers to use Uniform Resource Identifiers (URI) to play songs and to select, edit, and publish photos.
Use the Song.FromUri
method to construct a Song
object based on the
specified URI. Use the MediaLibrary.SavePicture
method to save images to the media library.
Modified and Added Classes and Methods
A fairly large number of classes and methods have been added or modified. You can view a full list on Microsoft’s MSDN website at http://msdn.microsoft.com/en-us/library/bb417503.aspx.
Test Your Knowledge: Quiz
Get Learning XNA 4.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.