5. Adding Resources to a Project
An XNA Game
Studio project contains references to everything that it uses. To keep
things simple, you can keep everything used by a project in a single
file directory. Figure 5
shows the content of the JakeDisplay project directory that XNA Game
Studio created for you when you made the new project. You can see the C#
source files and also some other resources.
The project contains a Content directory. When you add an asset to this project, it is stored in this directory. Figure 6
shows the JPEG image of Jake that I used in my Pictures directory. You
need to place the picture that you want to use into a directory
somewhere on the computer.
You can either use one of
the graphics images that are available in the sample projects or create
your own picture at this point. Now that you have your graphics
resource, you can tell XNA Game Studio to use it. To do this, you need
to add the content to the project. Resource references are added by
using the Add Existing Item – Content dialog box, which can be opened as
shown in Figure 7.
Start by right-clicking the JakeDisplay project’s Content item in
Solution Explorer. From the menu that appears, select Add and then
select Existing Item.
Figure 8 shows the dialog box that you can use to select an item to add to the project.
Now you can select the image file that you want to use and click Add to add it. The project now contains the resource. Figure 9 shows the resource reference in the project once you’ve added it. You follow the same process to add other images to a game.
If you want to add more
than one image to a project, simply repeat the process. Remember that
each image is stored as part of the game program, so the more images you
add, the larger your game becomes and the longer it takes to transfer
it into the target when it runs.
Note:
The
Xbox and Windows PC have plenty of memory in which to store loaded
images. However, the Zune device is restricted in the space that it has
available. If you want to store lots of pictures in the Zune, you need
to use small images (320 x 240 pixels or less) to make sure that you
don’t run out of space.
5.1. Adding Links to Resources
When you add a
resource using the process described previously, XNA Game Studio makes a
copy of the resource and places the copy in the Content directory of
the project. If you want several projects to share a single copy of a
resource, you can add a link to it instead. You do this by clicking the
down arrow at the right of the Add button in the Add Existing item
dialog box, as shown in Figure 10, which allows you to add the resource as a file or as a link.
Each
time XNA Game Studio builds the game, it follows the link to the
resource to use it. If the resource is moved or deleted, the build
process fails.
5.2. The XNA Content Pipeline
The process of feeding resources in at one end and getting a complete game assembly out of the other is a bit like a pipeline. In fact, the XNA Framework refers to this part of the game-building process as the Content Management Pipeline.