Game Component Development

Describes how to use XNA Game Studio to develop custom game components for your game projects. You derive the new component either from the GameComponent class, or, if the component loads and draws graphics content, from the DrawableGameComponent class. For more information about existing game component support in the XNA Framework, see the Game Components section of Application Model Overview.

Developing Custom Components

XNA Game Studio supports the development of custom game components for use in your game code. You can use the Add New Item dialog box to insert basic code for implementing a new component.

To insert a new custom game component

  1. Open an XNA Framework game or library project in XNA Game Studio.
  2. In Solution Explorer, right-click the game project node.
  3. Click Add, and then click New Item.
  4. In the Add New Item dialog box, in the Categories pane, select XNA Game Studio 3.0
  5. In the Templates pane, select the Game Component icon.
  6. Enter a name for the source file, and then click Add.

The new code is composed of three main methods.

Method NamePurpose
GameComponent1 The constructor for the game component. The name matches the name you specified when you inserted the new component. Add code that initializes the component here.
Initialize Called by the framework when the component starts. Add the component-specific starting code here.
Update Called by the framework when the component needs to be updated. Add the component-specific update code here.

After creating the new component, add your custom code to provide the necessary functionality.