How To: Add a Game Asset to Your Game
This example demonstrates how to add a texture asset to your game. The same procedure can also be applied to model and sound assets. It is assumed that an existing Windows or Xbox 360 game project is loaded in XNA Game Studio.
For information on loading content at runtime, see How To: Load Content.
For information on drawing a texture as a sprite, see How To: Draw a Sprite.
To add the texture asset to the game project
- From the Solution Explorer window, right-click the Content node, click Add, and then click Existing Item.
- Navigate to the location of the texture and select it. For this example, the asset is called B1_nebula01.tga.
Click the small arrow to the right of the Add button, and then click Add as Link. This creates a reference to the selected asset (and not a copy) in your project.
Making a reference to an existing asset in your project is quite different than adding an existing item to your project. A file reference stores only the path to the asset in question, not a copy of the contents. This is useful if the referenced asset is dependent on additional external assets and ensures that the latest version is always used by the solution. This differs from adding a copy of the asset to the project. In this case, it is possible to break external dependencies and create extra work if the original content changes but the copy is not updated.
For these reasons, it is recommended that any media used by the solution be in the nested content project of your solution and that a reference to the asset is added and not a copy.
After adding the asset to the solution, open the Properties window to verify that the proper importer and processor are specified (right-click on the file in Solution Explorer and choose Properties from the context menu). For this example, the Content Importer is Texture - XNA Framework and the Content Processor is Texture - XNA Framework.
For more information on the Properties window of a game asset, see Game Asset Properties.
- Save the solution.