Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Input;
- namespace Canvas
- {
- public class InputManager : GameComponent
- {
- public InputManager(CanvasGame g) : base(g)
- {
- Game.Services.AddService(typeof(InputManager), this);
- }
- KeyboardState currentKeyboardState;
- KeyboardState oldKeyboardState;
- MouseState currentMouseState;
- MouseState oldMouseState;
- public override void Update(GameTime gameTime)
- {
- oldKeyboardState = currentKeyboardState;
- currentKeyboardState = Keyboard.GetState();
- oldMouseState = currentMouseState;
- currentMouseState = Mouse.GetState();
- base.Update(gameTime);
- }
- public bool IsKeyDown(Keys k)
- {
- return (oldKeyboardState.IsKeyUp(k) && currentKeyboardState.IsKeyDown(k));
- }
- public bool IsKeyUp(Keys k)
- {
- return (oldKeyboardState.IsKeyDown(k) && currentKeyboardState.IsKeyUp(k));
- }
- public MouseState GetState()
- {
- return currentMouseState;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment