Update src/shapes/Sprite.js

Sprites now scale to their width and height correctly in the same way as images
This commit is contained in:
Taylan
2012-12-05 18:43:58 +00:00
parent 71eacd85d3
commit 33c7d1f2f6

View File

@@ -32,6 +32,8 @@
var anim = this.attrs.animation; var anim = this.attrs.animation;
var index = this.attrs.index; var index = this.attrs.index;
var f = this.attrs.animations[anim][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) { if(this.attrs.image) {
@@ -39,16 +41,18 @@
context.rect(0, 0, f.width, f.height); context.rect(0, 0, f.width, f.height);
context.closePath(); 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) { drawHitFunc: function(context) {
var anim = this.attrs.animation; var anim = this.attrs.animation;
var index = this.attrs.index; var index = this.attrs.index;
var f = this.attrs.animations[anim][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.beginPath();
context.rect(0, 0, f.width, f.height); context.rect(0, 0, width, height);
context.closePath(); context.closePath();
this.fillStroke(context); this.fillStroke(context);
}, },