public override bool Update(GameTime gameTime, TouchCollection currentTouch, out TouchStateBase nextState) { if (currentTouch.Count != 2) { TouchStateMachine.SubmitGestureEvent(new TwoFingeredDragEventArgs(GestureTiming.Completed, new Vector2())); nextState = new CooldownState(); return(true); } if (currentTouch[0].TryGetPreviousLocation(out var prevFinger1) && currentTouch[1].TryGetPreviousLocation(out var prevFinger2)) { nextState = null; if (!Vector2.Normalize(prevFinger1.Position - currentTouch[0].Position) .MovingInSameDirection(Vector2.Normalize(prevFinger2.Position - currentTouch[1].Position))) { TouchStateMachine.SubmitGestureEvent(new TwoFingeredDragEventArgs(GestureTiming.Completed, new Vector2())); nextState = new RotateAndScaleState(); return(true); } } var midpoint = Vector2.Lerp(currentTouch[0].Position, currentTouch[1].Position, 0); TouchStateMachine.SubmitGestureEvent(new TwoFingeredDragEventArgs(GestureTiming.InProgress, midpoint)); nextState = null; return(false); }
public override bool Update(GameTime gameTime, TouchCollection currentTouch, out TouchStateBase nextState) { switch (currentTouch.Count) { case 1: nextState = new DragState(); TouchStateMachine.SubmitGestureEvent(new DragEventArgs(GestureTiming.Started, currentTouch[0].Position)); return(true); case 2: TouchStateMachine.SubmitGestureEvent(new RotateAndScaleEventArgs(GestureTiming.Started, 0, 0)); nextState = new RotateAndScaleState(); return(true); default: // bail because no gesture is active anymore nextState = new WaitingState(); return(true); } }