Sunday 8 July 2012

Programming in C# with XNA – Visual Studio



You should now have all the elements you need to start writing your first game. What we will now do is launch Visual Studio. Once launched you should have a screen that looks a bit like this:-



Now my version of Visual Studio may look a little different to yours as I am using Visual Studio 2008. Visual Studio is also know as the Integrated Development Environment, IDE for short, this is where you will do all of your games programming. Lets open up our first project and see what we get to begin with.

At the top of the IDE you will see the menu, the first option there is File, click on that and you will get a list of options. Now click the first option in the list, New, then once that reveals another set of options, click on Project, it will look like this:




The IDE will now give you a dialog box which will look like this:




You will need to select the Visual C# item in the list on the left (Project types). Then in there you will see an option (or two) for XNA Game Studio, at the time of writing this post I have both 3.1 installed and so can create 3.0 and 3.1 projects. Select the XNA Game Studio Project type and you will see the Templates panel on the right will change and look like this:




Now we have quite a few options here, a Windows Game project, Xbox 360 project, Zune project, Content extension libraries and others. What we will be looking at is a Windows Game project, the one you can see highlighted in the image above. Now, before you click OK, there are a few things we need to be aware of.

At the bottom of this window are three input box’s. The first is quite important, this will be the name of your game, now if you want to change it at a later date, you can, it’s a bit fiddly, but you can so don’t worry if you haven't decided on what to put in here yet.

Next is the Location, this is where the code we are about to create will live on your machine.
The next is the Solution Name. Now a solution can hold many projects (projects contain whole games or parts of games, we will concentrate on writing one game in one project.), we will just have one in ours so we will give it the same name as our game (first input box).

We also have two check box’s, the first if checked (it is by default) will create a directory for the solution. The second is if you have Visual Source Safe, I am guessing most of you wont as you are hobbyists, but if you can get a copy it’s great for keeping your source safe (as the name suggests), there is nothing worse than losing all your code and not having a backup.. believe me I know a few guys who have had it happen, not nice..

So, I am going to call my project RCProgrammingTutorial, the solution name automatically changes to the new name too and the window now looks like this:



Click OK and the IDE will go off and create you a new Windows Game project by that name and under that solution based on the template we chose. We now have an IDE that looks like this:







There is a lot there isn’t there. Well with any luck I am going to now help you understand it all :) First I will start with the three windows we currently have in the IDE. The first and largest is the code view, here is where we are able to edit our source files, make changes and additions to code. In the top right hand corner is the Solution View (Solution Explorer), here we can see the whole of our solution, as I said before, we can have more than one project in a solution, here we have our project and in it quite a few things for us to look at in the next paragraph :D and next in the bottom right corner is the Properties View, we wont touch on this much, but it’s an important view none the less.

Solution View (Solution Explorer)


I know I have said we can have multiple projects in there, but we will just be using one for now, the RCProgrammingTutorial. As you can see in this project, we have a number of items to explore, lets go through them one at a time.

Properties


[Forgive the change in window skin, I got a new laptop while writing this post..]


As you can see this holds a single source file called AssemblyInfo.cs. In this file we can alter a few things, but the only one we are really interested in at the moment is AssemblyDescription, this entry is what will describe our game to the world, later when we deploy to our Xbox 360 when we go to view our game we will be able to see what is written here. For now I am going to give a short description as can be seen in the image below.




References


Again another important section, but no real need to go into detail here, but if we want to access other .NET functionality then we need to add it here first. I will explain a bit more when we get onto the act of programming.

Content


Now this will be a busy place for us, we will be adding lots of stuff here, I am going to start by adding a number of folders here ready for us to use later. To create a new folder here, right click on the Content branch and you will get a pop up menu like this.




Now move your mouse over the “Add” option and another menu will pop up, left click on “New Folder”

We will now have a new folder in the Content branch, name this folder “Textures”, then do the same again and create folders called, “Fonts”, “Shaders” and “Models”, the last two we probably wont use but create them anyway. In these new folders we can store the assets that we are going to use in our game, having these folders helps you to structure your assets so you can locate them quickly and easily.

You should now have a Content branch that looks something like this:




As well as these areas we can see we have a number of files here to. There is a Game.ico, this is the icon file that is used when you run the game in windows, if you double click it you can edit it and so create your own windows game icon. There is also a GameThumbnail.png, again you can double click and edit this too, this will be the image used to represent the game on the Xbox. We also have two source files, Program.cs and Game1.cs, these are the two key files we are going to look at in the nest post.

This post has rambled on for far too long, in the next post we will cover the basics of programming and with any luck get into the meat and potatoes of it all :)

Previous | Next

No comments:

Post a Comment