Developing Game-Themed Applications with XNA Game Studio
Section I: Introduction and Overview
b. The bare bone XNA Application
back to workshop main page
Goals:
- Experience with XNA Game Studio (GS) with the application
wizard.
- Understand the files and solution structure of applications created by
the wizard.
- Analyze the default application structure.
Notice:
- The Solution Explore and the actual underlying file system has a 1-to-1
correspondence.
- The ordering of functions being called by the
XNA framework:
- Constructor is called first.
- Initialization() is call next,
- LoadContent() is then called
- followed by continuous calling of:
- Update() - to update the application state:
should not draw anything!
- Draw() - to draw the application state:
should not change anything (i.e., do not perform any update operations)!
Project Creation: Start Game Studio Express
- File->NewProject
- Select: Window Game (2.0)
- Name: Type in SimpleXNA
- check: Create directory for solution
- Location: select your favorite location (e.g.,
Desktop)
- Click on OK.
- Build -> Build Solution
- Debug -> Start Debugging: we will see
This is our first XNA application. This is a very simple application perfect for
us to analyze:
- The files that are created by the Wizard
- The structure of the IDE
- The structure of the application
Understand the Files and Folder Structure: Open up Microsoft Explorer and navigate to
Desktop/SimpleXNA, we observe:
| Folder/File |
Purpose |
| SimpleXNA.sln |
.sln - this is the solution file of the entire project. |
| SimpleXNA.suo |
.suo - this is data file that XNA GS uses. We will not change
this files. |
| SimpleXNA/Game1.cs |
This file contains the Game1 class. This is the main
file we will work with. |
| SimpleXNA/Game1.ico
|
This is the graphical icon on the title bar of the running program. |
| SimpleXNA/GameThumbnail.png |
This is the graphical file for representing this game on the XBOX
360 console. By default, this looks like a some circles |
| SimpleXNA/Program.cs |
This is the container class of the Game1 class. |
| SimpleXNA/SimpleXNA.csproj |
This is the project description file for the .sln
solution file. In general, a solution (one .sln file) can consist of
many different projects (many .csproj) files. |
| SimpleXNA/bin and obj |
Compile result. As the names suggests, obj contains the
compile object files, while bin contains the executable binary
files. |
| SimpleXNA/Properties/AssemblyInfo.cs |
Description for the project, e.g., name to appear on the window
title bar. |
| SimpleXNA/Content/Content.contentproj |
This is the content project description file. As will be discussed,
fonts, file texture images, and audio wave files are examples of
contents. We will need to describe how these contents will integrate
into our project via this "content project". |
| SimpleXNA/Content/bin
and obj |
Build results from the content project. |
Understand the IDE solution structure: Now, go back to XNA GS,
- View->Solution Explorer: and you will see the follow
sub-window located at the right of GSE:
- Notice the structure of this solution corresponds 1-to-1 to the file
system structure
.- The References folder includes
information of which external libraries are required to support this
application. We will see an example of working with references later when we
need to include the XnaAssignmentBase library.
We can examine some of the files in our project (double click on the files to
open them in the editor):
- Assembly.cs: this file contains description of information for
the application. E.g., AssemblyTitle is the text in the title bar of
our application window.
- Program.cs: this is a container class for the Game1.cs class.
- Game1.cs: this is the source code we will work with. Notice there
are six functions:
- Game1(): this is the constructor.
- Initialize(): initialize the application state.
- LoadContent(): load contents (e.g., audio file, file texture
images, and fonts).
- UnloadContent(): Unload contents as the application exists.
- Update(): updates the application's state
- Draw(): draws the application's state
Understand the structure of the application: Now, go back to GSE,
- Insert a break-point in each of the above six functions
- By: Debug -> Toggle Breakpoint.
- Now, run the application again by:
- By: Debug -> Start Debugging
- Notice the ordering of the above six functions being invoked:
- Constructor is called first. Our program should allocate any
memory required. In the default case, the memory for
GraphicsDeviceManager is allocated.
- Initialization() is call next, this is where we should
initialize all the memory being allocated in the constructor.
- LoadConttent() is then called. This is where we will load the
contents for our application.
- After the above three functions are invoked, we will notice
continuous calling of:
- Update() - to update the application state:
should not draw anything!
- Draw() - to draw the application state:
should not change anything (i.e., do not perform any update operations)!
This calling sequence is true for all XNA applications. To build an
interactive application, all we have to do is to change the application
state according to user input during Update() and draw the changed state in Draw(). In the
next two examples, we will examine how to define/draw graphical objects and
interactively control graphical objects.
This document and the related materials are developed with support from
Microsoft Research Computer Gaming Initiative under the Computer Gaming
Curriculum in Computer Science RFP, Award Number 15871, and 16531.