Skip to content

Commit 04d81ad

Browse files
author
Tim Mickel
committed
Merge pull request scratchfoundation#89 from ScottLogic/sprite-sprite-collisions
Sprite stamping
2 parents 30d7e75 + cbdcbc3 commit 04d81ad

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

js/Sprite.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,15 +534,19 @@ Sprite.prototype.updateCachedPenColor = function() {
534534
};
535535

536536
Sprite.prototype.stamp = function(canvas, opacity) {
537-
var drawWidth = this.textures[this.currentCostumeIndex].width * this.scale;
538-
var drawHeight = this.textures[this.currentCostumeIndex].height * this.scale;
537+
var resolution = this.costumes[this.currentCostumeIndex].bitmapResolution || 1;
538+
var drawWidth = this.textures[this.currentCostumeIndex].width;
539+
var drawHeight = this.textures[this.currentCostumeIndex].height;
539540
var drawX = this.scratchX + (480 / 2);
540541
var drawY = -this.scratchY + (360 / 2);
542+
var rotationCenterX = this.costumes[this.currentCostumeIndex].rotationCenterX;
543+
var rotationCenterY = this.costumes[this.currentCostumeIndex].rotationCenterY;
541544
canvas.globalAlpha = opacity / 100.0;
542545
canvas.save();
543546
canvas.translate(drawX, drawY);
547+
canvas.scale(this.scale / resolution, this.scale / resolution);
544548
canvas.rotate(this.rotation * Math.PI / 180.0);
545-
canvas.drawImage(this.mesh, -drawWidth/2, -drawHeight/2, drawWidth, drawHeight);
549+
canvas.drawImage(this.mesh, -rotationCenterX, -rotationCenterY, drawWidth, drawHeight);
546550
canvas.restore();
547551
canvas.globalAlpha = 1;
548552
};

0 commit comments

Comments
 (0)