I use the following code to measure the velocity of a free drag gesture, but it doesn’t work with MonoGame. I set a breakpoint in the following line but it never gets executed. I tested the code on my Nokia Lumia 920.
isThisFirstTime = true;
Why is GestureType.DragComplete not working with MonoGame? Is it possible to fix this problem?
My code:
float DragVelocity, DragDistance, DragTime;
TimeSpan time;
Vector2 StartPoint, EndPoint;
bool isThisFirstTime = true;
TouchPanel.EnabledGestures = GestureType.FreeDrag;
protected override void Update(GameTime gameTime)
{
while (TouchPanel.IsGestureAvailable)
{
GestureSample gs = TouchPanel.ReadGesture();
switch (gs.GestureType)
{
case GestureType.FreeDrag:
if (isThisFirstTime == true)
{
time = TimeSpan.Zero;
StartPoint = new Vector2(gs.Position.X, gs.Position.Y);
isThisFirstTime = false;
}
else
{
EndPoint = new Vector2(gs.Position.X, gs.Position.Y);
time += gameTime.ElapsedGameTime;
}
break;
case GestureType.DragComplete:
isThisFirstTime = true;
DragTime = (float)time.TotalSeconds;
DragDistance = Vector2.Distance(StartPoint, EndPoint);
if (DragTime != 0)
DragVelocity = DragDistance / DragTime;
break;
}
}
base.Update(gameTime);
}