本文整理汇总了C#中Microsoft.Xna.Framework.Input.Touch.TouchLocation.TryGetPreviousLocation方法的典型用法代码示例。如果您正苦于以下问题:C# TouchLocation.TryGetPreviousLocation方法的具体用法?C# TouchLocation.TryGetPreviousLocation怎么用?C# TouchLocation.TryGetPreviousLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Input.Touch.TouchLocation
的用法示例。
在下文中一共展示了TouchLocation.TryGetPreviousLocation方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
internal static Motion Create( TouchLocation location, bool is8D )
{
Motion motion = new Motion ( );
switch ( location.State )
{
case TouchLocationState.Invalid:
motion.Type = MotionType.None;
break;
case TouchLocationState.Pressed:
motion.Type = MotionType.Down;
break;
case TouchLocationState.Moved:
motion.Type = MotionType.Press;
break;
case TouchLocationState.Released:
motion.Type = MotionType.Up;
break;
}
motion.Position = location.Position / World.Scale;
TouchLocation prevLocation;
if ( location.TryGetPreviousLocation ( out prevLocation ) && prevLocation.State != TouchLocationState.Invalid )
motion.Offset = ( location.Position - prevLocation.Position ) / World.Scale;
return motion;
}
示例2: AgeStateUpdatesPreviousDetails
public void AgeStateUpdatesPreviousDetails([Values(true, false)] bool isSameFrameReleased)
{
var touch = new TouchLocation(1, TouchLocationState.Pressed, new Vector2(1, 2), TimeSpan.FromSeconds(1));
if (isSameFrameReleased)
touch.SameFrameReleased = true;
touch.AgeState();
TouchLocation previous;
Assert.True(touch.TryGetPreviousLocation(out previous));
Assert.AreEqual(TouchLocationState.Pressed, previous.State);
Assert.AreEqual(touch.Id, previous.Id);
Assert.AreEqual(touch.Position, previous.Position);
Assert.AreEqual(touch.Timestamp, previous.Timestamp);
}
示例3: ProcessDrag
private void ProcessDrag(TouchLocation touch)
{
bool dragH = GestureIsEnabled(GestureType.HorizontalDrag);
bool dragV = GestureIsEnabled(GestureType.VerticalDrag);
bool dragF = GestureIsEnabled(GestureType.FreeDrag);
if (!dragH && !dragV && !dragF)
{
return;
}
/* Make sure this is a move event and that we have
* a previous touch location.
*/
TouchLocation prevTouch;
if ( touch.State != TouchLocationState.Moved ||
!touch.TryGetPreviousLocation(out prevTouch) )
{
return;
}
Vector2 delta = touch.Position - prevTouch.Position;
// If we're free dragging then stick to it.
if (dragGestureStarted != GestureType.FreeDrag)
{
bool isHorizontalDelta = Math.Abs(delta.X) > Math.Abs(delta.Y * 2.0f);
bool isVerticalDelta = Math.Abs(delta.Y) > Math.Abs(delta.X * 2.0f);
bool classify = dragGestureStarted == GestureType.None;
/* Once we enter either vertical or horizontal drags
* we stick to it... regardless of the delta.
*/
if ( dragH &&
( (classify && isHorizontalDelta) ||
dragGestureStarted == GestureType.HorizontalDrag ) )
{
delta.Y = 0;
dragGestureStarted = GestureType.HorizontalDrag;
}
else if ( dragV &&
( (classify && isVerticalDelta) ||
dragGestureStarted == GestureType.VerticalDrag ) )
{
delta.X = 0;
dragGestureStarted = GestureType.VerticalDrag;
}
/* If the delta isn't either horizontal or vertical
* then it could be a free drag if not classified.
*/
else if (dragF && classify)
{
dragGestureStarted = GestureType.FreeDrag;
}
else
{
/* If we couldn't classify the drag then
* it is nothing... set it to complete.
*/
dragGestureStarted = GestureType.DragComplete;
}
}
// If the drag could not be classified then no gesture.
if ( dragGestureStarted == GestureType.None ||
dragGestureStarted == GestureType.DragComplete )
{
return;
}
tapDisabled = true;
holdDisabled = true;
GestureList.Enqueue(
new GestureSample(
dragGestureStarted,
touch.Timestamp,
touch.Position,
Vector2.Zero,
delta, Vector2.Zero
)
);
}
示例4: AcceptTouchLocation
protected override bool AcceptTouchLocation(TouchLocation touchLocation)
{
if(touchLocation.State != TouchLocationState.Pressed)
{
return false;
}
TouchLocation previousLocation;
if (!touchLocation.TryGetPreviousLocation(out previousLocation))
{
previousLocation = touchLocation;
}
if (this.TouchArea.Contains(previousLocation.Position))
{
return true;
}
return false;
}
示例5: AcceptTouchLocation
protected override bool AcceptTouchLocation(TouchLocation touchLocation)
{
TouchLocation previousLocation;
if (!touchLocation.TryGetPreviousLocation(out previousLocation))
{
previousLocation = touchLocation;
}
if (Vector2.Distance(previousLocation.Position, this.CenterPosition.Value) < this.Radius)
{
return true;
}
return false;
}
示例6: ProcessDrag
private static void ProcessDrag(TouchLocation touch)
{
bool flag1 = TouchPanel.GestureIsEnabled(GestureType.HorizontalDrag);
bool flag2 = TouchPanel.GestureIsEnabled(GestureType.VerticalDrag);
bool flag3 = TouchPanel.GestureIsEnabled(GestureType.FreeDrag);
TouchLocation aPreviousLocation;
if (!flag1 && !flag2 && !flag3 || (touch.State != TouchLocationState.Moved || !touch.TryGetPreviousLocation(out aPreviousLocation)))
return;
Vector2 delta = touch.Position - aPreviousLocation.Position;
if (TouchPanel._dragGestureStarted != GestureType.FreeDrag)
{
bool flag4 = (double) Math.Abs(delta.X) > (double) Math.Abs(delta.Y * 2f);
bool flag5 = (double) Math.Abs(delta.Y) > (double) Math.Abs(delta.X * 2f);
bool flag6 = TouchPanel._dragGestureStarted == GestureType.None;
if (flag1 && (flag6 && flag4 || TouchPanel._dragGestureStarted == GestureType.HorizontalDrag))
{
delta.Y = 0.0f;
TouchPanel._dragGestureStarted = GestureType.HorizontalDrag;
}
else if (flag2 && (flag6 && flag5 || TouchPanel._dragGestureStarted == GestureType.VerticalDrag))
{
delta.X = 0.0f;
TouchPanel._dragGestureStarted = GestureType.VerticalDrag;
}
else
TouchPanel._dragGestureStarted = !flag3 || !flag6 ? GestureType.DragComplete : GestureType.FreeDrag;
}
if (TouchPanel._dragGestureStarted == GestureType.None || TouchPanel._dragGestureStarted == GestureType.DragComplete)
return;
TouchPanel._tapDisabled = true;
TouchPanel._holdDisabled = true;
TouchPanel.GestureList.Enqueue(new GestureSample(TouchPanel._dragGestureStarted, touch.Timestamp, touch.Position, Vector2.Zero, delta, Vector2.Zero));
}
示例7: ProcessTouch
public bool ProcessTouch(TouchLocation touch)
{
if (Texture == null)
return false;
bool touchHandled = false;
switch (touch.State)
{
case TouchLocationState.Pressed:
if ((touch.Position.X > Position.X - Origin.X) &&
(touch.Position.X < Position.X - Origin.X + Texture.Width) &&
(touch.Position.Y > Position.Y - Origin.Y) &&
(touch.Position.Y < Position.Y - Origin.Y + Texture.Height))
{
touchId = touch.Id;
touchHandled = true;
}
break;
case TouchLocationState.Moved:
if (touchId.HasValue && touchId.Value == touch.Id)
{
TouchLocation previousTouch;
touch.TryGetPreviousLocation(out previousTouch);
Position += touch.Position - previousTouch.Position;
// Fire the event!
if (PositionChanged != null)
PositionChanged(this, EventArgs.Empty);
touchHandled = true;
}
break;
case TouchLocationState.Released:
if (touchId.HasValue && touchId.Value == touch.Id)
{
touchId = null;
touchHandled = true;
}
break;
}
return touchHandled;
}