Introduction to XNA

(X.N.A. stands for Xna Not Acronymed)

What is XNA?

<from http://msdn.microsoft.com/directx/xna/faq/>

Q: What is XNA Game Studio Express?
A: XNA Game Studio Express is a new offering, targeted at students and hobbyists for game development. XNA Game Studio Express is based on Visual C# Express 2005 and lets developers target both Windows and Xbox 360. XNA Game Studio Express contains the following:

XNA is composed of two components;

  1. XNA Game studio Express (XNA GSE), which is a development environment built on top of Visual C# Express 2005
  2. XNA Framework, a set of .NET based libraries, a set of libraries designed for game development (XNA is based on, but will replace the Managed DirectX framework)

XNA Game Framework

The XNA framework is a set of interconnected classes designed to make game programming simpler. The most important class is the Game class. The Game class will be subclassed to create the application class. The Game class automatically call functions to;

Two other important classes are;

  1. GraphicsDeviceManager. Objects of this class represents the drawing device, all drawing will be done throught this class
  2. ContentManager. This class is part of the content pipeline, it will be used to load and dispose of game content.

 

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WindowsGame1
{
    /// 
    /// This is the main type for your game
    /// 
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// 
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// 
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

        /// 
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// 
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
        }

        /// 
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// 
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// 
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// 
        /// 
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here


            base.Update(gameTime);
        }

        /// 
        /// This is called when the game should draw itself.
        /// 
        /// 
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}

Component Model

Removed from XNA 1.0 release, not known if it will return...

Content Pipeline

The most important development with XNA is the content pipeline, which provides a seamless approach to dealling with content created by DCCs.

The content Pipline is broken into 4 stages. The first stages are carried out as part of the overall build process, the final stage happens at runtime. The content pipeline designed to ensure thet game assests are complete, up-to-date and in the most efficient format for game processing.

Importers

Importers convert from Digital Content Creation (DCC) tools into an XNA ready format for further processing, converting for example, a .x model file into an internal XML/XNA format.

XNA comes standard with several Importers (.x, .fbx, .jpg, .bmp, .fx, .xap etc), but new importers are easily created and added, and it is expected that importers will be eventually produced for every file format used in games production.

Content Processor

Performs some processing on the content after it has been imported. The different type of content after importing are Models, Textures, Materials, Effects, Audio. The content processor will perform project specific processing on the data prior to use. E.g. compiling an effect for the target shader model, or creating Mipmaps from the texture.

New game specific content processors can be added to the build cycle.

Serializer

The serializer converts the code into a compact binary format for quick runtime loading.

Loader

The content loader loads the assets at runtime. Because the assets are now in a standard XNA format, the loading process is quite simple for the programmer.

 

At a higher level, a build coordinator controls the Content Pipeline, the build coordinator also controls the normal compile/link build cycle, so the entire project, code and assets are build in one keystroke.

 

XNA automatically chooses correct importers and processors for the supported file types, but importers and processors can be choosen manually using the property window of the project files.