1

I am trying to learn how to use the touchmove event in browser to detect multitouch gestures. When a touchmove event is captured I can obtain a list of current touch points. However that is not very useful for detecting gestures. I like to get the history of the touch event. For example I want to get a list of last 10 touch points (if available) that came before each current distinct touch point. I draw the figure below in an attempt to visualize what I am after:

enter image description here

As I said in this scenario where the user is dragging two seperate fingers on the screen in two different patterns (fingers from different hands), I receive only two touch points inside the touchmove event. Is it possible to access history of where each of the two points have been before they got to the point A and B?

Here is the relevant bit of code for capturing the touchmove event:

document.addEventListener('touchmove', touchMove, false);

function touchMove(e) {
  console.log("length is: ", e.touches.length);
  e.preventDefault();
}

Please do not suggest third party libraries -- my goal is to learn how to define and detect my own custom true multitouch gestures.

Aras
  • 5,878
  • 9
  • 49
  • 76

1 Answers1

2

Yes, you can store the previous positions in arrays and iterate over them.

  1. Reset the history of them in the touchstart event
  2. Inside of the touchmove event, push the current coordinates as an object onto each array, identified via the identifier property of the Touch object. You can access the coordinates at the pageX and pageY properties of the Touch object available in event.targetTouches. To only store 10, callslice(-10)` after you've pushed onto the array.
alex
  • 479,566
  • 201
  • 878
  • 984
  • 1
    if I reset history of them on `touchstart` wouldnt I loose history of all touches? Note that they are indipendant touch points and their start/finish time is independent of other touches. It would be awesome if you could point me to an example, or write a bit of code to demonstrate how this can be done. – Aras Jun 21 '13 at 02:14