public void Update(GameTime gameTime, InputState inputState) { if (inputState.RightMousePressed()) { Point offset = new Point(inputState.LastMousePosition.X - inputState.MousePosition.X, inputState.LastMousePosition.Y - inputState.MousePosition.Y); _Screen.Offset(offset); } if(inputState.MouseScrolledUp() || inputState.KeyDown(Keys.PageUp)) { ZoomIn(inputState.MousePosition); } else if (inputState.MouseScrolledDown() || inputState.KeyDown(Keys.PageDown)) { ZoomOut(); } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public void Update(GameTime gameTime, InputState inputState) { Ticks++; if (this.Game.IsActive) { GUI.Update(inputState); UserInterfaceMessage guiMessage; while (GUI.GetMessage(out guiMessage)) { switch (guiMessage) { case UserInterfaceMessage.Play: this.State = GameState.Playing; break; case UserInterfaceMessage.Pause: this.State = GameState.Paused; break; case UserInterfaceMessage.Step: this.State = GameState.Paused; Map.Tick(); Ticks = 0; break; default: string message = "Unrecognized GUI Message '" + guiMessage.ToString() + "'."; throw new InvalidOperationException(message); } } if (inputState.KeyDown(Keys.Space)) { if (this.State == GameState.Paused) { this.State = GameState.Playing; } else { this.State = GameState.Paused; } } if (inputState.KeyDown(Keys.Escape)) { SetupMap(); } Camera.Update(gameTime, inputState); if (!inputState.MouseInputHandled && inputState.LeftMouseUp()) { Point clickedCell = Camera.GetCellCoordinatesOfClick(inputState.MousePosition); Map.FlipCell(clickedCell.X, clickedCell.Y); } } if (this.State == GameState.Playing && Ticks >= TickRate) { Map.Tick(); Ticks = 0; } }
public void Update(InputState inputState) { foreach (Control thisControl in Controls) { thisControl.HandleInput(inputState); } }
public virtual void HandleInput(InputState inputState) { LastControlState = ControlState; foreach (Control child in ChildControls) { child.HandleInput(inputState); } if (!inputState.MouseInputHandled && Position.Contains(inputState.MousePosition)) { inputState.MouseInputHandled = true; if (inputState.LeftMouseDown()) { ClickStartedHere = true; } if (inputState.LeftMousePressed()) { ControlState = ControlState.Clicked; } else if (inputState.LeftMouseUp()) { if (ClickStartedHere) { //Handle Click Event if (OnClick != null) { OnClick(this, EventArgs.Empty); } } else { //Don't handle event because it was a dragged click } } else { ControlState = ControlState.Hover; } } else { ClickStartedHere = false; ControlState = ControlState.Inactive; } }