Global keyboard states

Posted by Petr Abdulin on Game Development See other posts from Game Development or by Petr Abdulin
Published on 2012-04-02T05:28:15Z Indexed on 2012/04/02 5:43 UTC
Read the original article Hit count: 441

Filed under:
|

I have following idea about processing keyboard input. We capture input in "main" Game class like this:

protected override void Update(GameTime gameTime)
{
    this.CurrentKeyboardState = Keyboard.GetState();

    // main :Game class logic here

    base.Update(gameTime);

    this.PreviousKeyboardState = this.CurrentKeyboardState;
}

then, reuse keyboard states (which have internal scope) in all other game components. The reasons behind this are 1) minimize keyboard processing load, and 2) reduce "pollution" of all other classes with similar keyboard state variables.

Since I'm quite a noob in both game and XNA development, I would like to know if all of this sounds reasonable.

© Game Development or respective owner

Related posts about XNA

Related posts about architecture