Just as when we detected keypresses, we add an event listener and give the name of a function we want called when this event occurs.
In this case, we've called myCanvas.addEventListener, which means we only want to hear about it when it occurs on myCanvas. Otherwise we'd get notified of mouse movements all over the screen.
We also define the function, which I've chosen to call MyMouseMoveHandler, and it accepts a parameter that will be filled with information about the event. The exact information depends on the event.
Try moving your mouse around the canvas and seeing how the numbers change. Clearly something is wrong. Can you tell what it is ?
We'll now do the same example, but for touch.
|