Skip to content

Commit 30ef2b1

Browse files
authored
Merge pull request #497 from adroitwhiz/set-costume-size-synchronously-2
Set SVG skin size synchronously
2 parents 1371b6f + ad62542 commit 30ef2b1

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/SVGSkin.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,19 @@ class SVGSkin extends Skin {
114114
* @fires Skin.event:WasAltered
115115
*/
116116
setSVG (svgData, rotationCenter) {
117-
this._svgRenderer.fromString(svgData, 1, () => {
117+
this._svgRenderer.loadString(svgData);
118+
119+
// Size must be updated synchronously because the VM sets the costume's `size` immediately after calling this.
120+
// TODO: add either a callback to this function so the costume size can be set after this is done,
121+
// or something in the VM to handle setting the costume size when Skin.Events.WasAltered is emitted.
122+
this.size = this._svgRenderer.size;
123+
if (typeof rotationCenter === 'undefined') rotationCenter = this.calculateRotationCenter();
124+
this._viewOffset = this._svgRenderer.viewOffset;
125+
// Reset rawRotationCenter when we update viewOffset.
126+
this._rawRotationCenter = [NaN, NaN];
127+
this.setRotationCenter(rotationCenter[0], rotationCenter[1]);
128+
129+
this._svgRenderer._draw(1, () => {
118130
const gl = this._renderer.gl;
119131
this._textureScale = this._maxTextureScale = 1;
120132

@@ -147,13 +159,6 @@ class SVGSkin extends Skin {
147159
this._maxTextureScale = testScale;
148160
}
149161

150-
this.size = this._svgRenderer.size;
151-
if (typeof rotationCenter === 'undefined') rotationCenter = this.calculateRotationCenter();
152-
153-
this._viewOffset = this._svgRenderer.viewOffset;
154-
// Reset rawRotationCenter when we update viewOffset.
155-
this._rawRotationCenter = [NaN, NaN];
156-
this.setRotationCenter(rotationCenter[0], rotationCenter[1]);
157162
this.emit(Skin.Events.WasAltered);
158163
});
159164
}

0 commit comments

Comments
 (0)