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.

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 4.0 Refresh
  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 Purpose
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.

See Also

Advanced Topics
Getting Started with XNA Game Studio Development