So far, we've learned how to draw on the canvas, work with images and video, and create fluid animations. This chapter focuses on canvas interactivity. Until now, all of our canvas projects have been very unresponsive and disengaged from the user. Although the HTML5 canvas API doesn't provide us with a means for attaching event listeners to shapes and regions, we can certainly achieve this functionality by extending the API. According to the HTML5 specification, once a shape is drawn, we have no access to it as an object like we do with DOM elements in an HTML document. Until the HTML5 canvas specification includes methods for attaching event listeners to shapes and regions, (hopefully it will some day), we'll need to construct our own Events class which will enable us to do so. Our class will enable us to attach event listeners to regions which wrap one or more shapes, similar to attaching event listeners to DOM elements.
This is quite a powerful notion because it enables us...