Instead of the function being called MyMouseMoveHandler, I've chosen to it MyTouchMoveHandler -- but those are just names I made up in the interests of clarity, and they make no difference other than making it easier for humans to look at.
One important difference is we're listening for the touchmove event.
The other big difference is in how we read the coordinates. For the mouse, we just referred to:
The event comes equipped with an array called touches. For this example, we don't know how many fingers are on the screen, but we know there's at least one, so we access the first element of the array, which is at element zero.
If you're using a touch-sensitive device, try moving your finger around the canvas and seeing how the numbers change.
This example only works on touch-sensitive devices such as iPads or other tablets.
The same thing's wrong as for the mouse.
|