damongant

Untitled

Apr 22nd, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Input;
  7.  
  8. namespace Canvas
  9. {
  10. public class InputManager : GameComponent
  11. {
  12. public InputManager(CanvasGame g) : base(g)
  13. {
  14. Game.Services.AddService(typeof(InputManager), this);
  15. }
  16.  
  17. KeyboardState currentKeyboardState;
  18. KeyboardState oldKeyboardState;
  19.  
  20. MouseState currentMouseState;
  21. MouseState oldMouseState;
  22.  
  23. public override void Update(GameTime gameTime)
  24. {
  25. oldKeyboardState = currentKeyboardState;
  26. currentKeyboardState = Keyboard.GetState();
  27.  
  28. oldMouseState = currentMouseState;
  29. currentMouseState = Mouse.GetState();
  30. base.Update(gameTime);
  31. }
  32.  
  33. public bool IsKeyDown(Keys k)
  34. {
  35. return (oldKeyboardState.IsKeyUp(k) && currentKeyboardState.IsKeyDown(k));
  36. }
  37.  
  38. public bool IsKeyUp(Keys k)
  39. {
  40. return (oldKeyboardState.IsKeyDown(k) && currentKeyboardState.IsKeyUp(k));
  41. }
  42.  
  43. public MouseState GetState()
  44. {
  45. return currentMouseState;
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment