Example #1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            BoundingBox.X = (int)(Transform.X);
            BoundingBox.Y = (int)(Transform.Y);
            var mouse = Engine.Input.Mouse;

            if (BoundingBox.Contains(mouse.X, mouse.Y))
            {
                if (mouse.LeftClick)
                {
                    OnMouseClick(mouse.MouseData);
                    OnMouseClickEvent?.Invoke(mouse.MouseData);
                }
                else
                {
                    _mouseHovering = true;
                    OnMouseHover(mouse.MouseData);
                    OnMouseHoverEvent?.Invoke(mouse.MouseData);
                }
            }
            else
            {
                if (_mouseHovering)
                {
                    _mouseHovering = false;
                    OnMouseExit(mouse.MouseData);
                    OnMouseExitEvent?.Invoke(mouse.MouseData);
                }
            }
        }
Example #2
0
 // If the mouse position is negative or larger than the length/width of the screen resolution it means the mouse is out of bounds of the gamescreen.
 private void OnMouseHover(Vector2 myMousePosition)
 {
     OnMouseHoverEvent?.Invoke(this, myMousePosition);
 }