public KeyboardHandler(GameContext context) { IsEnabled = Environment.OSVersion.Platform != PlatformID.Xbox; KeyboardState = new Dictionary<Keys, InputState>(); if (IsEnabled) { keyboardBuffer = new KeyboardBuffer(context.Game.Window.Handle); keyboardBuffer.KeyPress += keyboardBuffer_KeyPress; keyboardBuffer.KeyDown += keyboardBuffer_KeyDown; } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { this.IsMouseVisible = true; this.graphics.PreferredBackBufferWidth = ScreenWidth; this.graphics.PreferredBackBufferHeight = ScreenHeight; this.graphics.ApplyChanges(); this.keyboardBuffer = new KeyboardBuffer(); this.mouse = new MouseHelp(); this.actorQueue = new PriorityQueue <IActor>(); base.Initialize(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // Create a new SpriteBatch, which can be used to draw textures. this.spriteBatch = new SpriteBatch(GraphicsDevice); this.graphics.PreferredBackBufferWidth = ScreenWidth; this.graphics.PreferredBackBufferHeight = ScreenHeight; this.graphics.ApplyChanges(); this.IsMouseVisible = true; this.keyboardBuffer = new KeyboardBuffer(); base.Initialize(); }
public void Action(GameTime time, KeyboardBuffer keyboard, MouseBuffer mouse) { if (keyboard.IsKeyDown(Key.W)) { Position.Y -= 1; } if (keyboard.IsKeyDown(Key.S)) { Position.Y += 1; } if (keyboard.IsKeyDown(Key.A)) { Position.X -= 1; } if (keyboard.IsKeyDown(Key.D)) { Position.X += 1; } }