Click to Rate and Give Feedback
MSDN
MSDN Library
XNA Game Studio
XNA Game Studio 3.1
 Load Generic Method
Collapse All/Expand All Collapse All
XNA Game Studio 3.1
ContentManager.Load Generic Method
Loads an asset that has been processed by the Content Pipeline.

Namespace: Microsoft.Xna.Framework.Content
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

C#
public virtual T Load<T> (
         string assetName
)

Type Parameters

T
The type of asset to load. Model, Effect, SpriteFont, Texture, Texture2D, Texture3D and TextureCube are all supported by default by the standard Content Pipeline processor, but additional types may be loaded by extending the processor.

Parameters

assetName
Asset name, relative to the loader root directory, and not including the .xnb file extension.

Return Value

The loaded asset. Repeated calls to load the same asset will return the same object instance.
Exception typeCondition
ObjectDisposedException Load was called after the ContentManager was disposed.
ArgumentNullException The assetName argument is null.
ContentLoadException The type of the assetName in the file does not match the type of asset requested as specified by T.

Before a ContentManager can load an asset, you need to add the asset to your game project using the steps described in Adding Game Assets to Your Game.

The following are the Content Pipeline run-time classes supported by Load and the file formats they are associated with.

Effect Class .fx
Model Class .fbx, .x
SpriteFont Class

.bmp, .spritefont, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga

Bb197848.note(en-us,XNAGameStudio.31).gifNote
The default content processor for .bmp files is the texture processor. To process a .bmp file for use as a Sprite Font, click Sprite Font Texture - XNA Framework in the Properties pane for the .bmp file after it has been added to the project.
Texture Class, Texture2D Class .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga
Texture3D Class, TextureCube Class .dds

Note that these are the formats of the original assets; after processing, all assets will be .xnb files.

To load a Model from the directory .\content\models\ with the asset name of "box":

C#
Model model = contentManager.Load<Model>( ".\\content\\models\\box" );
Xbox 360, Windows XP SP2, Windows Vista, Zune
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker