Game Creation with XNA/Basics/Visual Studio
Visual Studio edit
Visual Studio is quite a powerful tool. Some of its nicer features, however, are a little hidden. Hence, we first get you started with the basic features, but then also show some of the more advanced features .
Basic Feature edit
After starting Visual Studio you are presented with Visual Studio welcome page. It allows you to open existing projects or create new ones. One way to create a new project, click on 'File->New->Project'. A wizard starts, asking you what type of project you would like to start. For now let us simply create a 'Visual C#->Windows->Console Application'. Make sure you give it a name. After clicking the 'OK' button, Visual Studio will show you several windows, called
- Program.cs: this is the main editor window where you write your code
- Toolbox: especially when writing GUI programs for Windows, the lists many available GUI elements
- Error list: when there compiler errors or warnings they are displayed here
- Solution explorer: it lists the projects belonging to the solution, as well as the files and resources related to the project
- Properties: especially for GUI elements form the toolbox, the properties window allows you to change properties of those
An important feature of any IDE is debugging. Debugging allows you to run through your program line-by-line, watching variables as you go along, and even modifying them. In Visual Studio you do this via setting breakpoints. Simply double click on the grey bar to the left of the line of code where you want the execution to stop. Then hit 'F5' and the program starts and runs until it reaches the line with your breakpoint. You can also set multiple breakpoints if needed.
Advanced Features edit
Windows within Visual Studio can be rearranged to your liking, they can also be un-docked. It is also possible to view multiple documents by clicking on it and dragging it. Also it is possible to view different parts of the same document simultaneously. There is also a Full Screen Mode (Shift+Alt+Enter).
Code snippets can be used for reoccuring pieces of code. They can be added to the ’General’ section of the Toolbox. You use them via copy and paste. Also reoccuring comments (for class start etc) can be used this way. ToDo list is easy, you simply add ’// TODO: blabla’ in your code, and it will appear in the ToDo list.
XML commenting is done via typing ’///’. In the help system there is an ’XML Documentation Tutorial’.
Searching can be done via Find or via ’Find in Files’. You can search for text, but also for properties and methods. Another way to find methods is via the Code Window Combo Box. The best, however, is via the ’View>Class View’ window.
While debugging, it is possible to view and even change variables using the Command Window in Intermediate mode (Debug>Windows>Intermediate). To get the value of a variable type ’?’ and the variable name, to assign a new value use the ’=’ sign. As for breakpoints there are conditional breakpoints, this can be done in the ’New Breakpoint’ dialog box.
Short Cuts can be editied via ’Tools>Options’ in the Environment folder under the Keyboard section. Often used short-cuts are:
- Full Screen: Shift+Alt+Enter
- View Code: F7 (Shift+F7)
- Move Controls in Design mode: Ctrl+DownArrow
- Complete Word: Ctrl+Space
- Format Document: Ctrl+K, Ctrl+D
- Find: Ctrl+F (Ctrl+Shift+F), FInd Next: F3 (Shift+F3)
- Debug: F5 (Ctrl+F5), StepOver: F10, StepInto: F11 (Shift+F11)
- Deborah Kurata (2008). Best Kept Secrets in .NET. Apress