mirror of
https://github.com/scratchfoundation/scratch-render.git
synced 2025-08-28 22:30:04 -04:00
Set SVG skin size synchronously
This commit is contained in:
parent
7c4393787b
commit
94257a4214
1 changed files with 13 additions and 7 deletions
|
@ -114,7 +114,19 @@ class SVGSkin extends Skin {
|
|||
* @fires Skin.event:WasAltered
|
||||
*/
|
||||
setSVG (svgData, rotationCenter) {
|
||||
this._svgRenderer.fromString(svgData, 1, () => {
|
||||
this._svgRenderer.loadString(svgData);
|
||||
|
||||
// Size must be updated synchronously because the VM sets the costume's `size` immediately after calling this.
|
||||
// TODO: add either a callback to this function so the costume size can be set after this is done,
|
||||
// or something in the VM to handle setting the costume size when Skin.Events.WasAltered is emitted.
|
||||
this.size = this._svgRenderer.size;
|
||||
if (typeof rotationCenter === 'undefined') rotationCenter = this.calculateRotationCenter();
|
||||
this._viewOffset = this._svgRenderer.viewOffset;
|
||||
// Reset rawRotationCenter when we update viewOffset.
|
||||
this._rawRotationCenter = [NaN, NaN];
|
||||
this.setRotationCenter(rotationCenter[0], rotationCenter[1]);
|
||||
|
||||
this._svgRenderer._draw(1, () => {
|
||||
const gl = this._renderer.gl;
|
||||
this._textureScale = this._maxTextureScale = 1;
|
||||
|
||||
|
@ -147,12 +159,6 @@ class SVGSkin extends Skin {
|
|||
this._maxTextureScale = testScale;
|
||||
}
|
||||
|
||||
if (typeof rotationCenter === 'undefined') rotationCenter = this.calculateRotationCenter();
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue