Now let's make some changes to MySprite so it understands costumes.
- We're going to add a property called costume, which will control which particular costume is currently visible. It'll be zero by default.
- We'll add a second parameter which gets supplied when a MySprite is created. As well as supplying the url, we'll also supply the width of each costume. It's something we have to specify because it just depends on how we've drawn the image -- there's no way for a computer to tell just by looking at it.
- We'll take that number and store it in a property called costume_width.
function MySprite (img_url, width) {
this.x = 0;
this.y = 0;
this.visible= true;
this.costume = 0;
this.costume_width = width;
// etc
}
var kid = new MySprite("http://www.s2js.com/img/etc/boywalking.png", 115);