示例#1
0
        /// <summary>
        /// Returns true if the mouse hovers on specified position within radius
        /// </summary>
        /// <param name="targetPosition"></param>
        /// <param name="radius"></param>
        /// <returns></returns>
        public static bool IsMouseHoverOnTarget(Vector2 targetPosition, float radius)
        {
            MouseState mouseState = Mouse.GetState();

            if (CollisionDetection2D.IsNearTarget(new Vector2(mouseState.X, mouseState.Y), targetPosition, radius))
            {
                return(true);
            }
            return(false);
        }
示例#2
0
        /// <summary>
        /// Returns true if the mouse clicked on specified position within radius
        /// </summary>
        /// <param name="targetPosition"></param>
        /// <param name="radius"></param>
        /// <returns></returns>
        public static bool IsMouseClickedOnTarget(Vector2 targetPosition, float radius)
        {
            bool result = false;

            _mouseStateCurrent = Mouse.GetState();
            if (CollisionDetection2D.IsNearTarget(new Vector2(_mouseStateCurrent.X, _mouseStateCurrent.Y), targetPosition, radius))
            {
                if (_mouseStateCurrent.LeftButton == ButtonState.Pressed &&
                    _mouseStatePrevious.LeftButton == ButtonState.Released)
                {
                    result = true;
                }
            }
            _mouseStatePrevious = _mouseStateCurrent;
            return(result);
        }