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
- Open an XNA Framework game or library project in XNA Game Studio.
- In Solution Explorer, right-click the game project node.
- Click Add, and then click New Item.
- In the Add New Item dialog box, in the Categories pane, select XNA Game Studio 3.1
- In the Templates pane, select the Game Component icon.
- Enter a name for the source file, and then click Add.
The new code is composed of three main methods.
||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.|
||Called by the framework when the component starts. Add the component-specific starting code here.|
||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.