HTML and CSS Reference
In-Depth Information
Listing I.19. Listen to mouse events and update Wilson's target position
Note that you're not making any attempt to update the canvas within this handler. You
want all drawing to happen in the requestAnimFrame loop to minimize resource us-
age, so this function simply records the position and exits. If the browser is ready to make
use of the position, it will; otherwise, it will be replaced by the next mousemove event.
Step 4: Update the position of the image each time the animation is updated
So now you need a function to be called each animation frame to move Wilson toward the
current mouse position. The two functions in the listing that follows should be added to the
wilson object so that you can use them later.
Search WWH ::

Custom Search