9.13. Preloading Images

In many cases, you'd like the system to start loading the images as soon as possible, rather than waiting until you try to draw them with drawImage. This is particularly true if the images will not be drawn until the user initiates some action such as clicking on a button or choosing a menu option. That way, if the user doesn't act right away, the image might arrive before action is taken. You can use the prepareImage method to start the image loading in a background process and immediately return control to you. There are two versions of prepareImage, one for each version of drawImage:

prepareImage(image, window)

and

prepareImage(image, width, height, window)

Each time you stretch the image, it counts as a new one, ...

Get Core Web Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.