Sprite Component

A sprite component is an object that modifies the behavior of a sprite. Sprite components derive from the  base type that has exposes the following public contract:

Sprites contain a collection of sprite components to which individual sprite components can be added. Every frame, the  method is called on every component in the order in which they were added.

A sprite component can read and modify any of the public or internal members of a sprite. Typically, a sprite component only holds a reference to a Sprite object as its owner, which means that sprite components can only access those members that are defined in the base Sprite type. A sprite component can optionally contain a reference to a certain derived type of Sprite, but this is not recommended because it greatly reduces resuability.

Reusability of components means that a single component can be added to many different kinds of sprites to give that sprite a given behavior. For example, a walker component, which makes a sprite move a certain distance each frame, can be added to any sprite to give it the behavior of a walker.

Sprite components are generally unable to interact with each other, mostly because there's no guarantee that a sprite might have a sprite component that another component might access. In order to give a sprite component the behavior of other sprite components, or in order to allow a sprite component interaction with another, the concept of containment (not inheritance) may be used.

For example, a component which represents a shelled enemy may wish to contain a walker component within it. In the Update method, the shelled enemy component would call the walker's Update method, which would move the enemy. The concept of containment is very useful to amend and modify a component's behavior.