I thought about keeping the amount of pixels the user has dragged the screen, by keeping a sum of the delta’s returned in the gestureSample object, but these delta’s don’t seem to be consistent:
EnabledGestures = GestureType.HorizontalDrag | GestureType.DragComplete;
foreach (GestureSample gestureSample in input.Gestures)
{
if (gestureSample.GestureType == GestureType.HorizontalDrag)
{
_dragOffset += gestureSample.Delta.X;
System.Diagnostics.Debug.WriteLine("drag: " + _dragOffset + " - delta: " + gestureSample.Delta + " pos; " + gestureSample.Position);
}
}
The code above displays the following:
- drag: 0 – delta: {X:0 Y:0} pos; {X:692 Y:414}
- drag: -4 – delta: {X:-4 Y:0} pos; {X:683 Y:415}
- drag: -6 – delta: {X:-2 Y:0} pos; {X:676 Y:415}
- drag: -8 – delta: {X:-2 Y:0} pos; {X:669 Y:415}
- drag: -11 – delta: {X:-3 Y:0} pos; {X:658 Y:415}
- drag: -15 – delta: {X:-4 Y:0} pos; {X:644 Y:415}
The absolute position of the GestureSample moved by -7 pixels but the delta only reports -2!
This happens both on the emulator as a real WP7 device. Is my interpretation of delta incorrect and should I not rely on it?
I have found the issue: I was not processing all Gestures read from the TouchPanel. During 1 game cycle, multiple HorizontalDrag gestures can and will be recorded; they will not be merged into 1 gesture.
Solution: make sure to go over ALL GestureSamples.