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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.