Geeks With Blogs
Sharpoverride The road to becomming a good programmer is paved with bad scripts

Disclaimer: This is the first in a series of post from which we'll learn the bare minimum needed to build games by using the XNA framework. The guide assumes you have a good grasp of the C# programming language and some good understanding of the .NET Framework ecosystem.

Before we do anything else we need to go to http://creators.xna.com/en-US/downloads. Here we'll download the XNA Game Studio 3.1.

Note: I have Microsoft Visual Studio Team Edition as part of the Microsoft Student partner program, for those of you using the Express edition of Microsoft Visual Studio some of the functionality may not exist. I apologize in advance and we can continue with the learning.

After download you should start the installer process that will copy all the necessary files to the directory that you specify during the initial steps of the installation.

After the installer finished we can go in our Microsoft Visual Studio environment and by clicking File > New > Project.. (default shortcut CTRL+SHIFT+N).

 

 

 

 

 

After you can select XNA Game Studio 3.1 from the Project types and click on the Windows Game (3.1) Template. Give it a name: XnaQuestPart1.

 

 

 

 

 

 

 

 

 

 

 

 

Note: The hardware you write games on, or test games is very important! I only have a laptop with a basic Intel Integrated Graphics Chipset that can process some pixel shaders and vertex shader 2.0. As a consequence the games will be limited to what I can render on this hardware.

You should be able to press the Debug button and have a simple Graphics context running.

The game project is organized like a basic Console/WinForms application. The only part that differs is the Contents folder.

 

In the Contents folder you can copy/paste or Add New/Existing Items of the following types

  • Images: .gif, .jpeg, .png, .dds
  • 3D models saved in Direct X Format  .x or Autodesk Format .fbx

We have the option of extending the pipeline that handles this files and import additional formats but that is for another post.

 

 

 

 

 

The interesting part we should explore next is the Game1.cs file that the template generated for us.

The game class in Game1.cs is divided into 2 sections:

  • Initialization
  • Handling

In the initialization phase the GraphicsDevice is instantiated and the root directory for the content is set.

In the override of the Initialize() method we'll be able to add extra code for the instances we want to instantiate.

Note: The game framework will also call the Initialize() method of all the registered game components at this stage. About game components we'll discuss a bit later.

In the LoadContent() method you will load images, textures, models etc. If you have some custom content that is not managed by the ContentManager than you'll have to dispose of it in the UnloadContent() method.

There are two types of handling. One deals exclusively with the game logic, and the other one exclusively with the Drawing.

The Update() method should host all the logic for updating the computation (or game) logic. Usually you will find the input logic and the impact it has on the other instances of the game.

The Draw() method should deal exclusively with the parts that render on the screen or send some data to the underlying graphics hardware system.

Note: By default the Update() method is invoked 60 times per frame, and the Draw() method is called as many times as possible per frame. It is something XNA does behind the scenes and you should keep that in mind.

Hope you enjoyed this post and be sure to leave a comment to keep me going about XNA if you  should find this useful. This series of posts are as much for me as they are for you on the quest of learning some XNA and basic game programming stuff.

Posted on Saturday, August 8, 2009 5:51 AM | Back to top


Comments on this post: Quest: Learning XNA to build your own game

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Sharpoverride | Powered by: GeeksWithBlogs.net