How are components properly instantiated and used in XNA 4.0?

Posted by Christopher Horenstein on Game Development See other posts from Game Development or by Christopher Horenstein
Published on 2010-10-17T19:02:39Z Indexed on 2012/09/10 21:50 UTC
Read the original article Hit count: 253

Filed under:
|
|
|

I am creating a simple input component to hold on to actions and key states, and a short history of the last ten or so states. The idea is that everything that is interested in input will ask this component for the latest input, and I am wondering where I should create it.

I am also wondering how I should create components that are specific to my game objects - I envision them as variables, but then how do their Update/Draw methods get called?

What I'm trying to ask is, what are the best practices for adding components to the proper collections? Right now I've added my input component in the main Game class that XNA creates when everything is first initialized, saying something along the lines of this.Components.Add(new InputComponent(this)), which looks a little odd to me, and I'd still want to hang onto that reference so I can ask it things.

An answer to my input component's dilemma is great, but also I'm guessing there is a right way to do this in general in XNA.

© Game Development or respective owner

Related posts about XNA

Related posts about xna-4.0