Keep min and max scale in relative bounds as in Scratch 2.0

This commit is contained in:
Tim Mickel 2016-11-14 12:20:29 -05:00
parent 4deee071b2
commit a767c5ec79
No known key found for this signature in database
GPG key ID: 59C3D9D14D923146

View file

@ -249,9 +249,18 @@ RenderedTarget.prototype.setSize = function (size) {
if (this.isStage) { if (this.isStage) {
return; return;
} }
// Keep size between 5% and 535%.
this.size = MathUtil.clamp(size, 5, 535);
if (this.renderer) { 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(); var renderedDirectionScale = this._getRenderedDirectionAndScale();
this.renderer.updateDrawableProperties(this.drawableID, { this.renderer.updateDrawableProperties(this.drawableID, {
direction: renderedDirectionScale.direction, direction: renderedDirectionScale.direction,