MULTIMEDIA

Microsoft XNA Game Studio 3.0 : Displaying Images - Resources and Content (part 2) - Adding Resources to a Project

2/27/2011 10:47:05 AM

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.

Figure 5. The contents of the JakeDisplay project directory


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 6. My Jake image in my Pictures directory


Figure 7. Opening the Add Existing Item – Content dialog box


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.

Figure 8. The Add Existing Item – Content dialog box


Figure 9. The JakeDisplay project containing the image resource



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.

Figure 10. Adding the Jake image 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.

Other  
  •  iPhone 3D Programming : Blending and Augmented Reality - Rendering Anti-Aliased Lines with Textures
  •  Programming with DirectX : Game Math - Bounding Geometry (part 2) - Bounding Spheres & Bounding Hierarchies
  •  Programming with DirectX : Game Math - Bounding Geometry (part 1) - Bounding Boxes
  •  Programming with DirectX : Game Math - Matrices
  •  iPhone 3D Programming : Anti-Aliasing Tricks with Offscreen FBOs (part 2) - Jittering
  •  iPhone 3D Programming : Anti-Aliasing Tricks with Offscreen FBOs (part 1) - A Super Simple Sample App for Supersampling
  •  Building LOB Applications : Navigating RIA LOB Data
  •  Building LOB Applications : Databinding in XAML
  •  Microsoft XNA Game Studio 3.0 : Program Bugs
  •  Microsoft XNA Game Studio 3.0 : Getting Player Input - Adding Vibration
  •  Microsoft XNA Game Studio 3.0 : Getting Player Input - Using the Keyboard
  •  iPhone 3D Programming : Blending and Augmented Reality - Stencil Alternatives for Older iPhones
  •  iPhone 3D Programming : Blending and Augmented Reality - Poor Man’s Reflection with the Stencil Buffer
  •  Microsoft XNA Game Studio 3.0 : Getting Player Input - Reading a Gamepad
  •  iPhone 3D Programming : Blending and Augmented Reality - Shifting Texture Color with Per-Vertex Color
  •  iPhone 3D Programming : Blending and Augmented Reality - Blending Extensions and Their Uses
  •  iPhone 3D Programming : Blending and Augmented Reality - Blending Caveats
  •  Building LOB Applications : Using Visual Studio 2010 WCF RIA Data Services Tooling
  •  Building LOB Applications : Implementing CRUD Operations in WCF Data Services
  •  iPhone 3D Programming : Blending and Augmented Reality - Wrangle Premultiplied Alpha
  •  
    Top 10
    Windows Server 2003 : Domain Name System - Command-Line Utilities
    Microsoft .NET : Design Principles and Patterns - From Principles to Patterns (part 2)
    Microsoft .NET : Design Principles and Patterns - From Principles to Patterns (part 1)
    Brother MFC-J4510DW - An Innovative All-In-One A3 Printer
    Computer Planet I7 Extreme Gaming PC
    All We Need To Know About Green Computing (Part 4)
    All We Need To Know About Green Computing (Part 3)
    All We Need To Know About Green Computing (Part 2)
    All We Need To Know About Green Computing (Part 1)
    Master Black-White Copying
    Most View
    Microsoft Tries To Flatten Competition With Surface (Part 3) - Dropbox drops Public Folders, SSD Prices Way Down, AMD Adopts Arm for Armor
    SQL Server 2008 R2 : Dropping Indexes, Online Indexing Operations, Indexes on Views
    NZXT Source 210 Elite - Finest Cases For Frugal Gamers
    OLED Me Be the One
    Toshiba Tecra R850
    Windows 8's Unexpected Features (Part 1)
    Computing Yourself Fit (Part 4)
    Crucial Ballistix Tactical LP 16GB Kit
    100 Windows Speed-Up Tips (Part 1) - Clean up your hard drive & Defrag your computer
    Organize Windows With Virtual Desktops
    Developing Applications for the Cloud on the Microsoft Windows Azure Platform : DNS Names, Certificates, and SSL in the Surveys Application
    Improve Your Mac (Part 2) - Add Music To You Movies
    LG Optimus L3 E400 Review (Part 1)
    Roku 2 XS
    Get An Awesome Satnav For Free
    Windows 7 : Syncing with Network Files (part 2) - Dealing with Conflict
    KWA 150 SE – The Most Expensive Amplifier Of ModWright
    Kindle Fire - The Second Coming (Part 1)
    Essential Wedding Kit (Part 3) - Shoot-saving kit
    Web Security : Attacking AJAX - Checking for Cross-Domain Access, Reading Private Data via JSON Hijacking