Original Post
Hi everyone I have created a little game using the XNA framework.. I am currently trying to clean up my code, but I am having a little trouble. My game consists of many components which all needs to know the keyboard- and mouse state, but to save processing time i would like to just get these states ONCE per update cycle. I have tried adding these states as game.service's in my games main file (Game1.cs), getting the states each time the update is run, and then getting the services in each of the components which needs the states. /------------------------------------------------------------------------- Game1.cs public class Game1 : Microsoft.Xna.Framework.Game { . . private KeyboardState keyboardState; private MouseState mouseState; . . protected override void LoadContent() { Services.AddService(typeof (KeyboardState), keyboardState); Services.AddService(typeof(MouseState), mouseState); . . } protected override void Update(GameTime gameTime) { keyboardState = Keyboard.GetState(); mouseState = Mouse.GetState(); . . } . . } /---------------------------------------------------------------------------- SomeGameComponent { . . private KeyboardState keyboardState; private MouseState mouseState; . . public override void Update(GameTime gameTime) { mouseState = (MouseState)Game.Services.GetService(typeof(MouseState)); keyboardState = (KeyboardState)Game.Services.GetService(typeof(KeyboardState)); . . } /----------------------------------------------------------------------------- I Hope this makes sence.. I cant make this work, since the states i get from my game service dont update.. So my question is, is there a way to update your game services, or do i really have to get the mouse and keyboard states in every component that uses them?? (NB. these arent the only objects i would like shared, but also stuff like my player object and enemyManager). Yours sincerly Anders Nysom