First, just to be helpful, we realise we'll have plenty of MySprites that only have a single costume, so if the sprite was created without a costume_width being specified, we'll set the costume_width equal to the width of the entire image file.
Then for convenience, we add a couple of properties called h and w to the object, as a handy place to keep the height and width of the costume.
Finally, the thing we came here for: we alter drawImage to use all those widths and heights. Note we multiply the costume number by the width to find the costume within the image. It looks pretty confusing. If you want, go back and look and the preceding pages and understand why each parameter is what it is. Or, just trust that I've done it correctly.
Let's take it for a run and see if it works !
|