f you have ever dreamed of being a game developer (honestly, who among us has not toyed with the idea at least a little?), this is your time in the sun. With the release of XNA Game Studio Express in December of 2006, Microsoft has begun a steady march on a mission to change the game development industry.
Microsoft released XNA Game Studio Express as a beta in early August 2006, followed up with a second beta a few months later in November, and then officially released version 1.0 in December of 2006 to much excitement in the game development community. The initial audience to embrace XNA Game Studio Express has been game development hobbyists and small independent game shops, but it is clear that the game development community as a whole has its eye on XNA Game Studio Express—not only where it's going, but also where it's taking the game industry.
After a quick introduction of XNA Game Studio Express, this article shows you how to use it to create a simple 2D example game.
It's Good to Be Free!
One of the most attractive features of XNA Game Studio Express is its price. Everything you need to make a game with XNA Game Studio Express is...free! Developers who want to use XNA Game Studio Express also use C# Express, giving them the power and speed of developing with managed code in a free development environment. The only costs to game developer hopefuls are the art and sound assets, which in many cases they can find for free, or create with free tools. It is pretty hard to argue with a price like that.
Even if you can afford XNA Game Studio Express, you must make sure that your computer can actually handle developing with it. Hardware requirements primarily consist of not having an older video card. You need a Direct3D 9.0 video card capable of at least Shader Model 1.1. You can purchase cards that meet this minimum requirement fairly inexpensively from most major computer electronic retailers. Some people with older laptops might have to jump this hurdle, but most users won't have trouble meeting the minimum requirements.
|What does XNA stand for? It's a recursive acronym that stands for "XNA's Not Acronymed."|
Getting started with XNA Game Studio Express starts with learning C#. While you don't need to be a C# expert to learn to use XNA Game Studio Express, you will need to have a basic understanding of the syntax and the initial concepts of object-oriented programming.
If you are fairly familiar with C# and you have some experience with DirectX development, you may wonder where the tutorial and sample code are that show how to set up a graphic device and display that first black screen. Talking to the graphics device and getting a good blank slate is always a good first step in a game project. This was quite an arduous task with DirectX, particularly for newcomers.
To help prevent that frustration with XNA Game Studio Express, here's a walk-through of that initial "first game" project to get you started, with slow and detailed steps so you won't spend an entire evening getting through this first game development step.
Making That First Game Project
Here's the process in a nutshell:
- Launch XNA Game Studio Express. You'll see the familiar C# Express development environment. XNA Game Studio Express is basically that standard environment, with some extra XNA Framework goodies thrown in.
- Click the File menu and select New Project.
- Select the "Windows Game" project template.
- Give your new game a name and click OK.
- Run your game.
Yes, that's it! If you were greeted by a beautiful cornflower blue screen (it's the new black), then congratulations! The rest of the night is now yours to spend writing game logic rather than setting up communications with a graphics device.
You have just experienced a small part of the power of XNA Game Studio Express. To be fair, it is true that once you had established a communication with a graphics device with DirectX, you could have created your own "Windows Game" template—but the point of using XNA Game Studio Express is that you didn't have
to. Installing XNA Game Studio Express also installs a Windows Game template that lets new game developers get up and running quickly without all the confusion.
The Game Loop
Another great example of this kind of "out-of-the-gate" mentality in XNA Game Studio Express is the game loop. Traditional game development has always involved a great deal of thought and philosophical debate on how to construct and use a game loop. Many people put a lot of time into this, and new game developers often get lost just trying to wade through the many and differing discussions. New game developers just want to get started on their game, but getting started on a game loop can cause confusion.
With XNA Game Studio Express, game loops are no longer a research topic or a stumbling block for new game developers. When you create a new XNA Game Studio Express game, the game loop is already there—beneath the surface. Instead of developing the loop, game developers can immediately begin putting game logic into the pre-existing Update
method and display logic into the Draw
method. These methods are not only created automatically when you begin a new XNA Game Studio Express game, but they are called automatically by the hidden game loop and fire continuously during the life of the game. Developers can now begin actual game development instead of trying to figure out how to create an efficient game loop correctly.
The Content Pipeline
Since XNA Game Studio Express makes creating a new game project simple, and it takes care of creating an efficient game loop, what's next on the list of XNA Game Studio Express features that lowers the learning curve for new game developers? That would be the content pipeline. This feature of XNA Game Studio Express aids game developers in getting content into their games. Whether that content consists of models, backgrounds, textures, sprite sheets, music, sound effects, or XML files, Microsoft's content pipeline makes loading content a little easier and a bit more uniform.
Along with loading content, the content pipeline also makes it easier to distribute your games. The built-in content pipeline converts all your content pipeline-loaded assets to XNA binary files (XNB) files. XNB is a new file extension specific to XNA Game Studio Express. You ship the XNB files instead of your assets with your executable when you finally release your game. The content pipeline and the XNB files not only help keep track of your assets, but help protect them as well, because (at least right now) there are no tools that can extract them from the XNB file format back into the original asset files.
Now that you've seen an overview of how to load game content into your games in XNA Game Studio Express, it might be nice to have a way of getting some user input to control that content. For that, Microsoft has given game developers the very intuitive and extremely easy to use Keyboard, Mouse, and Gamepad objects along with corresponding "state" objects to gather information about those devices.
For example, suppose you want to know if a user has pressed the Escape key. You could do it like this:
Keys.Escape) == true)
The Keyboard object is already a part of XNA Game Studio Express, so developers do not need to create or initialize it. The Keyboard object just waits, ready to be used if needed. Getting information about mouse or gamepad devices is just as simple using the Mouse and Gamepad objects. In other words, gathering user input using XNA Game Studio Express is a snap.
You represent game components as GameComponent classes that you can add to your main game class. Each GameComponent class has its own Update
methods that are automatically called from the main game loop. This creates the potential for powerful plug-and-play opportunities in your game design. While the XNA community has not seen many generic pluggable game components appear yet, some early examples that calculate and display frames per second have appeared. As game developers get used to developing game components, adding rich game functionality to your game may become as easy as dropping in the appropriate GameComponent classes.
Yeah, I Made That
I've covered some of the basic features that showcase the power of XNA Game Studio Express, but I have not yet mentioned one of the most powerful and coolest features of the framework. The feature that has generated the most buzz and has some of the highest wow
factor is that you can play games you develop with XNA Game Studio Express on your Xbox 360. This feature, while cool, does come with a price. In order to play your creations on the Xbox 360, you need a membership to the Microsoft Creators Club, which runs around $99 for a year membership. Try to develop for any other console at that price! No other company has given the general public this kind of officially supported access for development on a console before, so this feature has great potential to start some changes in game development.
I wrote this article to give you an overview of XNA Game Studio Express and a brief glimpse of its power. As you begin to play with XNA Game Studio Express yourself, I am sure that you will have questions. Since I cannot possibly hope to answer all of your questions here (or even in a series of articles), I'll point you to the Microsoft's Creator's Club
site to get your questions answered.
The Creators Club site is not only a great place to grab some Microsoft XNA Game Studio Express content such as new starter kits and samples, but it also has some of the most active support forums I have ever seen. You'll find support from XNA community members, but even more importantly, the extremely helpful and knowledgeable XNA Game Studio Express developers at Microsoft also monitor the forums. If you post a question, you are sure to get an answer, often within hours, if not minutes, of your initial post.
The community around XNA Game Studio Express has been amazing and helpful right from the very beginning. I'd be neglectful if I do not at this point mention some of the great sites, resources, and games provided by the XNA Game Studio Express community (see sidebar, Community
With all of this power in XNA Game Studio Express and an active and growing community, how do you go about increasing the XNA Game Studio Express fever? You hold a game development competition and make the grand prize so attractive that game developers around the world from hobbyists to indies to professional houses want a shot at it. Microsoft has done that with their Dream Build Play competition
. With a $10,000 grand prize and the potential for an Xbox LIVE Arcade publishing contract, this competition has most of the community working feverishly to get their game ideas completed and coded in time.
Now that you have learned a little about XNA Game Studio Express and the XNA Framework, let me show you how to make a game!
|Editor's Note: This article was first published in the September/October 2007 issue of CoDe Magazine, and is reprinted here by permission.