Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Complete Sample
The code in this topic shows you the technique for loading content. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.
Loading Content
You need a content project in your game if you are using Visual Studio 2010 Express to compile and build your project. For more information, see How to: Add Game Assets to a Content Project.
To load content and ensure it is reloaded when necessary
Derive a class from Game.
Override the LoadContent method of Game.
In the LoadContent method, load your content using the ContentManager.
SpriteBatch spriteBatch; // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); myTexture = Content.Load<Texture2D>("mytexture"); }
Override the UnloadContent method of Game.
In the UnloadContent method, unload resources that are not managed by the ContentManager.
protected override void UnloadContent() { // TODO: Unload any non ContentManager content here }
See Also
Reference
Game Class
LoadContent
UnloadContent
Game Members
Microsoft.Xna.Framework Namespace