From a767c5ec790a010448e5fdbe334d071753118c35 Mon Sep 17 00:00:00 2001 From: Tim Mickel Date: Mon, 14 Nov 2016 12:20:29 -0500 Subject: [PATCH] Keep min and max scale in relative bounds as in Scratch 2.0 --- src/sprites/rendered-target.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index 89270397a..50ad7e8f5 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -249,9 +249,18 @@ RenderedTarget.prototype.setSize = function (size) { if (this.isStage) { return; } - // Keep size between 5% and 535%. - this.size = MathUtil.clamp(size, 5, 535); if (this.renderer) { + // Clamp to scales relative to costume and stage size. + // See original ScratchSprite.as:setSize. + var costumeSize = this.renderer.getSkinSize(this.drawableID); + var origW = Math.round(costumeSize[0]); + var origH = Math.round(costumeSize[1]); + var minScale = Math.min(1, Math.max(5 / origW, 5 / origH)); + var maxScale = Math.min( + (1.5 * this.runtime.constructor.STAGE_WIDTH) / origW, + (1.5 * this.runtime.constructor.STAGE_HEIGHT) / origH + ); + this.size = Math.round(MathUtil.clamp(size / 100, minScale, maxScale) * 100); var renderedDirectionScale = this._getRenderedDirectionAndScale(); this.renderer.updateDrawableProperties(this.drawableID, { direction: renderedDirectionScale.direction,