Visual Studio 2008 for Gaming: Introduction to Microsoft XNA Game Studio 3.0

Create and develop games the easy way. In this overview seminar get an introduction to Microsoft XNA Games Studio 3.0 and learn the object-oriented tools to develop your own games for Windows, Zune and the Xbox 360 console.

Download

Video Transcript

Welcome and Introduction

Welcome to Visual Studio for Gaming: Introduction to Microsoft XNA Game Studio 3.0. Now, of course the goal of this session is tor provide a high level introduction to Microsoft XNA Game Studio 3.0. And in a nut shell it’s simply a tool set that allows you build games that target windows, Zune and the Xbox 360 console. You can download it for free at http://creators.xna.com.

There’s a number of goals of XNA Game Studio 3.0. First and foremost is to enable aspiring game developers. In the past, people who have good ideas for games often times find it hard to get those games produced. Number one, they don’t know how, number two, they don’t have access to game development contracts. They may not have access to development kits or the development kits are prohibitively expensive. In some cases, game development kits for consoles in the past have cost thousands or even tens of thousands of dollar. So, XNA Game Studio brings game development to the masses. Traditionally, writing game is pretty difficult and it’s generally regarded as this black art that involves lots of late nights and pizza and caffeine and lots of this sort of arcane knowledge.

One of the goals of XNA Game Studio is to just handle all the heavy lifting so that game developers can just worry about sort of the game play aspects and just worry about making a great, really fun playable game. Another thing that relates to that is the fact that since XNA Game Studio is built on the XNA Framework. which is a managed .NET Framework, that means that you use the C# and familiar object oriented techniques. So, you take a language that’s thousands upon thousands of developers are already familiar and they’ve already got a head start into being able to create their own games.

Finally, one the goals of XNA Game Studio is to provide an educational solution. Aand if you look at colleges and universities they’re always looking at ways at increasing interest in their computer science programs and what better way than to teach computer science topics such as logic and syntax and graphics but do so with games where students have the opportunity to write their games. There’s certainly a lot of interest in those classes and we’ve seen, you know, certain outtake in interest in computer science when you’ve got programs like this involved.

Installation

So as far as installation is concerned, before you install XNA Game Studio Express, you’ll need to make sure that you have Windows Vista Service Pack One or Windows XP Service Pack Tree. You’ll also need some version of Visual Studio or Visual C# 2008 Express Edition. If you have any version of Visual Studio 2008, then you’re already fine. If you’ve got Visual C# 2008 or rather, if you do not have Visual Studio 2008 at all, then you can download for free Visual C# 2008 Express Edition and that could also serve as your platform for installing XNA Game Studio. In addition to the tools, you’ll need the DirectX runtime, direct 3-D 9.0 video card, and they recommend Shader Model 2.0.

I mentioned already that it’s multi-platform and that is the XNA Game Studio targets Windows Xbox and Zune. It does so in a slightly different ways for each one. On Windows based PCs, XNA targets the .NET framework 2.0. On the Xbox and the Zune, it’s going to target the .NET compact framework. And the only difference between the two of them is clearly the manner of input devices and the graphics capabilities and the resolution and everything for the Xbox. But also the fact that Zune does not support 3-D, whereas the Xbox 360 console does. So let’s take a quick look at some of the factors involved in developing with XNA Game Studio.

XNA Game Studio

First of all, let’s take a look at the platform itself. So, the platform again, is multi targeting for Windows, Xbox and Zune. On top of the platform, you’ve got the XNA Framework which is a managed framework so it runs within .NET, either the regular .NET 2.0 or the compact framework and the high level components of the XNA Framework are an application model and a content pipeline. Now the content pipeline is used to bring in the various sorts of gaming assets into your application or into your game and so that would be textures and models and graphics and audio and so forth.

Having a content pipeline is important because the assets come from various programs and in various formats and they all need to be in a consistent format in order to be able to be rendered within the XNA environment. So it has importers and processors that handle all that for you and if you have one of the less common types of content, then you can even build your own content importers and processors to handle that.

Now the application model consists of a number of class libraries. There’s, of course, the graphics API, there’s audio APIs to make playing background music and sound effects really simple. There’s a lot of mass support because especially when you’re dealing with 3-D content, you have to do quite a bit of mathematical calculations, input would be being able to grab input from the user via game pad or the keyboard or the mouse. Networking, of course, in the PC version is going to be sort of standard Windows and .NET networking but when you’re dealing with the Xbox, the networking aspect of the XNA Framework allows you to create through Xbox live multiplayer games that you can play on the Xbox so there’s a lot of Xbox specific application there.

Finally, there’s gamer services and that allows you to tie in to the profiles system that’s used by Xbox 360. So XNA Game Studio sits on top of that and it requires Visual Studio 2008. It provides a lot of the components for the content pipe line and it also has a device management utility that we’ll be seeing in just a bit.

Game Flow

The basic game flow and you’ll see this in just about every XNA session that you view is all about update and draw. Your game, of course, is gonna start one of the early things that it must do is load all of it’s content and that’s where the importers and processors are involved. And then, it gets to the point where it’s in the game loop and the game loop consists of updating the logic; and that’s where you would poll for user input, that’s where you would manipulate objects in terms of their position and their coordinates and their direction. And then draw where you actually take the models and the textures and put them on the screen.

It’s a game loop so as soon as you’re done drawing you go back and you update and you repeat until the game is over until the application of the game is closed. At that point, you unload content and that’s it. So, having this and a good understanding of this very simple game flow is pretty key to getting involved in XNA Game Studio because that’s the way all games are designed to work within the XNA Game Studio.

Now, the goal of the tool set is to enable a debug and testing experience that’s consistent with other forms of .NET development and that means that you hit F5 to test, you can put in break points, you can watch your local variables, you can step through a code, everything that you’re used to if you’re coming from a more traditional non-gaming .NET development environment. Everything is supported, just as you would expect it to and when you’re dealing with not just Windows development but development for Xbox and Zune.

Deploying to XBOX 360

I should want to say a few words about deploying to Xbox 360 because it’s not quite as straightforward as just building a Windows game, for instance. If you want to target Xbox 360, you will need to get a premium membership in the XNA creators club and at this point, it’s $49 for four months, $99 per year. But it gives you the ability to review and publish games, so review other peoples games and publish your own games. It gives you access to additional content. And by the way, that publishing aspect involves you getting paid for your games, you get to select how much you want to charge and I’ll talk a little bit more about that just a little later.

As far as deploying Xbox 360, another component that you need is called XNA Game Studio Connect and it’s something that you can download for free from Xbox LIVE Marketplace. It provides the connectivity between PC and Xbox 360. Even if you download it, it’s not going to do anything unless Xbox sees that premium membership. And that’s why you need the premium membership in order to deploy from the PC over to test on your Xbox.

 

On the PC side, the XNA Game Studio device center is what provides you with a way to manage your devices and whether that’s Zune or Xbox 360, you could have multiple instances of devices. It’s not something that you have to install separately, it just ships with XNA Game Studio 3.0 and you’ll see that in our demo, exactly what that looks like.

Demo

So, let’s take a look at sort of the ‘hello world’ of XNA Game Studio. So let’s fire up Microsoft Visual C# 2008 Express Edition. Now, I’m go into file, new project. And you’ll see that in the new project dialogue, because I have XNA Game Studio 3.0 installed, I have a number of templates that allow me to target Windows Xbox and Zune in developing games or game libraries. Now, in addition to the various individual platforms that you can target, you also have the ability to create games that target multiple platforms. And there’s some guidance online as to how to do that. There’s also guidance in the form of a platform or starter kit. So, if we go ahead and select that and click okay, you’ll see that this template will build us a nearly complete game that targets all three platforms. Over here in solution explorer, you’ll see we have a Zune copy of the platformer, we have an Xbox 360 copy of the platformer and finally we have a Windows based PC copy of the platformer.

So, these share code and content according to the sort of best practices, and so you can look at this as a guidance in developing cross platform games. Now you can also use is as a sort of a tutorial on 2-D game developing in general as well as being able to use the high resolution assets and content that is provided here. So you’ll have a number of high resolution backgrounds, fonts, levels, sprites and so forth. You can use those, you can see how this game uses them to get an example of sprite animation, collision detection, timing and so forth.

Let’s go ahead and just try this out, go ahead and start debugging. It’s going to build the version for Windows based PCs. And now, you’ll see we have a simple game that we control with either the Xbox game pad plugged in via USB or with our keyboard. It’s got music, it’s got sound, it’s got again, collision detection, it’s got backgrounds, animated sprites, everything that you need to sort of get you started in developing a 2-D platform game and it’s a great place to start, especially as you’re creating a platformer yourself.

So that’s a good place to sort of get some ideas and get the creative juices flowing. In our case, I’m going to go ahead and close the solution, cause I want to show you what it takes to build and deploy a game to Xbox 360.

We’re switching over to my Xbox 360 now so you can see what I looks like. I’m selecting the game market place and then, from the game market place, you’ll want to click on browse for content. And then, from browse, you’re going to go to genres and other, and then you need to go all the way down to the bottom of the list where you’ll find the XNA Creators Club. At that point, you can move over to select the XNA Game Studio Connect. Game Studio Connect is the application that allows us to deploy an application to Xbox 360 from our PC. Now, I’ve already downloaded it so I don’t need t download it now. I can just select play now and when it starts up, it’s going to display a simple blue screen with a key and I’m going to need that key to place into XNA Game Studio.

Okay, we click next and at this point, it’s now connecting to Xbox.

Back at the PC, we’re told we’ve successfully connected to the Xbox360 Console. At this point it should now show up in our device center. So let’s switch over to the Xbox and see what it looks like. Now, until this point, it will just show the key and then waiting there for a connect ion. I put in the key and we’re going to go ahead and call this one XNA Game Studio Device Center and the goal here is not

Up and running as quickly as possible. So the first thing I’m going to do is I’m going to add some content, just about every game I would wager to say, all games are going to require some sort of graphic content, so we’re going to go ahead and add a simple model. This one has already been created for us so we’ll go ahead, add an existing item, go to the desk top and import hellobox.fbx. When it goes into content, it already is given an asset name. One thing that we want to do in this particular case is we want to open up the properties for the content processor where we can fix, you know, rotations and change the scale and so forth and since this is a pretty small model, we’ll go ahead and give it a scale of 20.

Now I need to add some member variables. So, we’ll go ahead and do that right at the top. I’m building a 3-D game so I’m going to have to deal with camera position and some matrixes. I’ve also designed or defined a member variable that’s going to represent the 3-D model that I just imported. Speaking of which, I need to go down into the load content method and this is where we load the game content so we’ll go ahead and do that. We’re also going to use is a location to initialize our cameras view matrix and projection matrix but this is the actual content load right here. Notice that hello box matches the asset name that we specified or that was created for us over in Solution Explorer.

Next up we’re going to modify the update method. Remember the update method is called every 1/60 second by default and it’s typically where you’re going to want to do any polling for the user input if you want to check the keyboards state or the mouse state or the game pad state, you do it here. I’m just going to replace the default content with some of my own. What this does is it retrieves the game pad state for player one and then it checks to see if they’re pressing the back button in which case we leave the game. It also checks to see if we’re pressing the A button and we do nothing and then finally, it gets the value that’s being input by the left thumb stick and uses that to modify two floating values. So, in the update method is where we do all of our sort of game logic and then the draw method gets called in order to actually render the pixels to the screen so for that we’re going to need sort of a helper method called draw model, just to make things a little easy for us and because we’re dealing with a 3-D space, we need to draw the model along and in doing so, provide a world matrix, sort of to determine where that model should be in 3-D space.

Finally, we go over and add one more line of code and this is in the draw method. This is where we call draw model. We pass in the box that we loaded are 3-D modeling too and we create the rotation based on those values box X and box Y and if you remember, those are the ones that we updated based on the game pad state. So, we should be able at this point, build and hopefully, have it succeed and I just want to point out while we’re at it that the development and testing and debug experience should be identical to what you may be used to from using Visual Studio. So, what I can do here, is for instance, double click over and add a break point right in here, just to show how that works and then, once we’re ready to go we can simply hit F5 or click on the green start key to start debugging.

Now, let’s go ahead and stop from here. I can either use the game pads, press the back button which would exit the program but I can also control execution from the PC so I can pause or stop execution right here and that’s the ‘hello world’ for XNA Game Studio and developing on the Xbox 360.

XBOX Live Community Games

Now before we wrap up, I’d like to talk a little bit about Xbox LIVE community games, and this is probably the reason why a lot of people are going to be downloading XNA Game Studio because they recognize they have to have to create and sell their own games. Now the four steps involved in publishing your game or to get to that point, number one you got to create your games, that’s downloading the XNA Game Studio, starting to build your game, test your game, debug your game. You can do all that on your own Xbox with a premium membership in the Content Creators Club. Once you’ve gotten it to a point where you feel it’s ready and you’ve removed the bugs, it’s not crashing and you feel like it’s playable and it’s ready to go, then you submit it. And when you submit your game, it’s going to go into this sort of area that’s not public and as a premium member of the Content Creator’s Club, you and all of your peers will be able to view those games that are in that status and offer comments, suggestions, help track down problems, bugs, watch our for intellectual property violations and it’s sort of a self policing arena there.

At some point, it’s going to get approved and once your game is approved, then it gets moved over into the public side of Xbox Live Marketplace and now anybody who has an Xbox Live membership regardless of whether they even know that Content Creator Club exists they’re able to download purchase and play your game throughout all this, you own your own intellectual property and of course, the caveat is you get to keep your own IP and therefore, you don’t get to steal other people’s IP and that’s part of what that peer review is for.

Now, when you publish your game, you get to pick the price now since people are using points in Xbox Live, you pick a certain number of points that you’d like to charge but that equates to real money and when it equates to real money, you get to keep 70 percent of the amount that you charge.

Currently, Xbox LIVE in terms of community games, is not available everywhere. From a consumer standpoint, consumers can purchase Xbox LIVE community games if they live in the US, Canada, England, France, Italy and Spain. If you want to be a creator, you just have to live in any of those countries plus Ireland, Norway, Sweden and the Netherlands.

So, what should you take away from this brief session, well, number one, you can start building games today and they’ve made it as easy as they can in order to do that. The cost of entry for building Windows PC games is nothing. You can download Visual C# 2008 Express Edition for free. You can download XNA Game Studio 3.0 for free and again, you can get started right away. Now if you’re willing to get a premium membership in the XNA Creators Club, you can publish your games to Xbox LIVE Marketplace and you can start having your games pay you. Thanks as always, and I hope to see you again in the future at another session.

[End of Audio]