예제 #1
0
        /// <summary>
        /// Performs input handling for the Load Level UI grid in lieu of default grid drag.
        /// </summary>
        /// <param name="camera"></param>
        public override void HandleTouchInput(Camera camera)
        {
            TouchContact touch = TouchInput.GetOldestTouch();

            if (touch == null)
            {
                return;
            }

            if (touch.phase == TouchPhase.Ended)
            {
                isDragging = false;
                return;
            }
            else if (!isDragging)
            {
                // This touch hasn't yet been classified as a drag yet.. so we
                // will see if it meets the criteria.
                float minDiff = MIN_DRAG_START;
                float diff    = (touch.position - touch.startPosition).Length();
                if (diff < minDiff)
                {
                    return;
                }
                else
                {
                    isDragging = true;
                }
            }

            // Get local coordinates difference between this touch position and the previous
            Matrix  localInvMatrix  = Matrix.Invert(LocalMatrix);
            Vector2 currentLocalPos = TouchInput.GetLocalXYFromScreenCoords(
                touch.position,
                camera,
                ref localInvMatrix);
            Vector2 previousLocalPos = TouchInput.GetLocalXYFromScreenCoords(
                touch.previousPosition,
                camera,
                ref localInvMatrix);
            float localXMove = (currentLocalPos - previousLocalPos).X;

            if (SlideByX(localXMove))
            {
                // We did a successful move, so capture the momentum of the touch in pixels/frame
                float duration = 1.0f;

                if (Math.Abs(localXMove) > 0.2f)
                {
                    residualVelocity    = localXMove / 4.0f;
                    hasResidualVelocity = true;
                    TwitchManager.Set <float> set = velocityDelegate;
                    TwitchManager.CreateTwitch <float>(residualVelocity, 0, set, duration,
                                                       TwitchCurve.Shape.EaseOut);
                }
                else if (touch.phase == TouchPhase.Stationary)
                {
                    // If the user has stopped moving but hasn't ended his touch, we will put
                    // the brakes on any residual velocity, as the user probably wants to settle
                    // here.
                    residualVelocity    = 0.0f;
                    hasResidualVelocity = false;
                }
            }
        }