/// <summary> /// Updates the elements. /// </summary> public void Update(GameTime gameTime, Vector2 mousePosition) { MouseInfo.Update(); KeyboardInfo.Update(); foreach (BaseElement element in this.elements) { element.Update(gameTime); } this.UpdateHoveredElement(); if (this.hoveredElement != null) { if (MouseInfo.LeftMouseClicked) { this.hoveredElement.LeftClick(); } if (MouseInfo.MouseWheelScrolledUp) { this.hoveredElement.MouseWheelScrollUp(); } if (MouseInfo.MouseWheelScrolledDown) { this.hoveredElement.MouseWheelScrollDown(); } if (MouseInfo.LeftMouseClicked) { this.heldElement = this.GetDraggableElement(); } } if (MouseInfo.LeftMouseDragged) { if (this.heldElement != null && this.heldElement.Draggable) { Vector2 delta = MouseInfo.Position - MouseInfo.PreviousPosition; Vector2 newPosition = this.heldElement.GetPosition() + delta; this.heldElement?.Move(newPosition); } } if (MouseInfo.LeftMouseReleased) { this.heldElement = null; } }
protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape) || gameManager.ReadyToExit) { Exit(); } // TODO: Add your update logic here MouseInfo.Update(); KeyboardInfo.Update(); gameManager.Update(); base.Update(gameTime); }