From 33c7d1f2f6d382490aa73a13f52638a0ddceb8cd Mon Sep 17 00:00:00 2001 From: Taylan Date: Wed, 5 Dec 2012 18:43:58 +0000 Subject: [PATCH] Update src/shapes/Sprite.js Sprites now scale to their width and height correctly in the same way as images --- src/shapes/Sprite.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/shapes/Sprite.js b/src/shapes/Sprite.js index 184d5891..ab8310bf 100644 --- a/src/shapes/Sprite.js +++ b/src/shapes/Sprite.js @@ -32,6 +32,8 @@ var anim = this.attrs.animation; var index = this.attrs.index; var f = this.attrs.animations[anim][index]; + var width = this.attrs.width || f.width; + var height = this.attrs.height || f.height; if(this.attrs.image) { @@ -39,16 +41,18 @@ context.rect(0, 0, f.width, f.height); context.closePath(); - this.drawImage(context, this.attrs.image, f.x, f.y, f.width, f.height, 0, 0, f.width, f.height); + this.drawImage(context, this.attrs.image, f.x, f.y, f.width, f.height, 0, 0, width, height); } }, drawHitFunc: function(context) { var anim = this.attrs.animation; var index = this.attrs.index; var f = this.attrs.animations[anim][index]; - + var width = this.attrs.width || f.width; + var height = this.attrs.height || f.height; + context.beginPath(); - context.rect(0, 0, f.width, f.height); + context.rect(0, 0, width, height); context.closePath(); this.fillStroke(context); },