Learn Create Your Own Split Screen

Next Page

The next step is to get those mouse variables updating when we wave the mouse around.

We do that by adding an event listener, and declaring a function that gets called every time a mouse move event occurs. The function calculates the correct coordinates within the canvas, and stores them in the variables.

If this sort of code seems a bit confusing and unfamiliar, you may need to go back and review Sensing the mouse and touches.

Move the mouse over the canvas and check the numbers change correctly.