diff --git a/src/SVGSkin.js b/src/SVGSkin.js index 90e3908..9c10e61 100644 --- a/src/SVGSkin.js +++ b/src/SVGSkin.js @@ -30,6 +30,24 @@ class SVGSkin extends Skin { /** @type {Number} */ this._maxTextureScale = 0; + + /** + * The natural size, in Scratch units, of this skin. + * @type {Array} + */ + this.size = [0, 0]; + + /** + * The viewbox offset of the svg. + * @type {Array} + */ + this._viewOffset = [0, 0]; + + /** + * The rotation center before offset by _viewOffset. + * @type {Array} + */ + this._rawRotationCenter = [NaN, NaN]; } /** @@ -43,21 +61,17 @@ class SVGSkin extends Skin { super.dispose(); } - /** - * @return {Array} the natural size, in Scratch units, of this skin. - */ - get size () { - return this._svgRenderer.size; - } - /** * Set the origin, in object space, about which this Skin should rotate. * @param {number} x - The x coordinate of the new rotation center. * @param {number} y - The y coordinate of the new rotation center. */ setRotationCenter (x, y) { - const viewOffset = this._svgRenderer.viewOffset; - super.setRotationCenter(x - viewOffset[0], y - viewOffset[1]); + if (x !== this._rawRotationCenter[0] || y !== this._rawRotationCenter[1]) { + this._rawRotationCenter[0] = x; + this._rawRotationCenter[1] = y; + super.setRotationCenter(x - this._viewOffset[0], y - this._viewOffset[1]); + } } /** @@ -134,7 +148,11 @@ class SVGSkin extends Skin { } if (typeof rotationCenter === 'undefined') rotationCenter = this.calculateRotationCenter(); - this.setRotationCenter.apply(this, rotationCenter); + this.size = this._svgRenderer.size; + this._viewOffset = this._svgRenderer.viewOffset; + // Reset rawRotationCenter when we update viewOffset. + this._rawRotationCenter = [NaN, NaN]; + this.setRotationCenter(rotationCenter[0], rotationCenter[1]); this.emit(Skin.Events.WasAltered); }); }