Use explicit rotationCenter argument
This is more explicit than the previous behavior, and more in line with the way we supply the costumeResolution
This commit is contained in:
parent
875a5a3ec1
commit
c478ebec35
@ -55,9 +55,10 @@ class BitmapSkin extends Skin {
|
|||||||
* Set the contents of this skin to a snapshot of the provided bitmap data.
|
* Set the contents of this skin to a snapshot of the provided bitmap data.
|
||||||
* @param {ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} bitmapData - new contents for this skin.
|
* @param {ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} bitmapData - new contents for this skin.
|
||||||
* @param {int} [costumeResolution=1] - The resolution to use for this bitmap.
|
* @param {int} [costumeResolution=1] - The resolution to use for this bitmap.
|
||||||
* @param {bool} [calculateRotationCenter=false] - Set the rotation center to the bitmap center
|
* @param {number[]=} rotationCenter - Optional rotation center for the bitmap. If not supplied, it will be
|
||||||
|
* calculated from the bounding box
|
||||||
*/
|
*/
|
||||||
setBitmap (bitmapData, costumeResolution, calculateRotationCenter) {
|
setBitmap (bitmapData, costumeResolution, rotationCenter) {
|
||||||
const gl = this._renderer.gl;
|
const gl = this._renderer.gl;
|
||||||
|
|
||||||
if (this._texture) {
|
if (this._texture) {
|
||||||
@ -79,7 +80,8 @@ class BitmapSkin extends Skin {
|
|||||||
this._costumeResolution = costumeResolution || 1;
|
this._costumeResolution = costumeResolution || 1;
|
||||||
this._textureSize = BitmapSkin._getBitmapSize(bitmapData);
|
this._textureSize = BitmapSkin._getBitmapSize(bitmapData);
|
||||||
|
|
||||||
if (calculateRotationCenter) this.setRotationCenter.apply(this, this.calculateRotationCenter());
|
if (typeof rotationCenter === 'undefined') rotationCenter = this.calculateRotationCenter();
|
||||||
|
this.setRotationCenter.apply(this, rotationCenter);
|
||||||
|
|
||||||
this.emit(Skin.Events.WasAltered);
|
this.emit(Skin.Events.WasAltered);
|
||||||
}
|
}
|
||||||
|
@ -140,11 +140,12 @@ class RenderWebGL {
|
|||||||
* Use `createBitmapSkin` or `createSVGSkin` instead.
|
* Use `createBitmapSkin` or `createSVGSkin` instead.
|
||||||
* @param {!string} skinUrl The URL of the skin.
|
* @param {!string} skinUrl The URL of the skin.
|
||||||
* @param {!int} [costumeResolution] Optional: resolution for the skin. Ignored unless creating a new Bitmap skin.
|
* @param {!int} [costumeResolution] Optional: resolution for the skin. Ignored unless creating a new Bitmap skin.
|
||||||
* @param {!boolean} [calculateRotationCenter] Optional: set the rotation center of the skin to the box center
|
* @param {number[]=} rotationCenter Optional: rotation center of the skin. If not supplied, the center of the skin
|
||||||
|
* will be used.
|
||||||
* @returns {!int} The ID of the Skin.
|
* @returns {!int} The ID of the Skin.
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
createSkinFromURL (skinUrl, costumeResolution, calculateRotationCenter) {
|
createSkinFromURL (skinUrl, costumeResolution, rotationCenter) {
|
||||||
if (this._skinUrlMap.hasOwnProperty(skinUrl)) {
|
if (this._skinUrlMap.hasOwnProperty(skinUrl)) {
|
||||||
const existingId = this._skinUrlMap[skinUrl];
|
const existingId = this._skinUrlMap[skinUrl];
|
||||||
|
|
||||||
@ -180,7 +181,7 @@ class RenderWebGL {
|
|||||||
url: skinUrl
|
url: skinUrl
|
||||||
}, (err, response, body) => {
|
}, (err, response, body) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
newSkin.setSVG(body, calculateRotationCenter);
|
newSkin.setSVG(body, rotationCenter);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -188,7 +189,7 @@ class RenderWebGL {
|
|||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.crossOrigin = 'anonymous';
|
img.crossOrigin = 'anonymous';
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
newSkin.setBitmap(img, costumeResolution, calculateRotationCenter);
|
newSkin.setBitmap(img, costumeResolution, rotationCenter);
|
||||||
};
|
};
|
||||||
img.src = skinUrl;
|
img.src = skinUrl;
|
||||||
}
|
}
|
||||||
@ -679,13 +680,8 @@ class RenderWebGL {
|
|||||||
}
|
}
|
||||||
// TODO: remove this after fully deprecating URL-based skin paths
|
// TODO: remove this after fully deprecating URL-based skin paths
|
||||||
if ('skin' in properties) {
|
if ('skin' in properties) {
|
||||||
const {skin, costumeResolution} = properties;
|
const {skin, costumeResolution, rotationCenter} = properties;
|
||||||
const skinId = this.createSkinFromURL(
|
const skinId = this.createSkinFromURL(skin, costumeResolution, rotationCenter);
|
||||||
skin,
|
|
||||||
costumeResolution,
|
|
||||||
// If no rotationCenter, calculate one
|
|
||||||
!('rotationCenter' in properties)
|
|
||||||
);
|
|
||||||
drawable.skin = this._allSkins[skinId];
|
drawable.skin = this._allSkins[skinId];
|
||||||
}
|
}
|
||||||
if ('skinId' in properties) {
|
if ('skinId' in properties) {
|
||||||
|
@ -53,9 +53,10 @@ class SVGSkin extends Skin {
|
|||||||
/**
|
/**
|
||||||
* Set the contents of this skin to a snapshot of the provided SVG data.
|
* Set the contents of this skin to a snapshot of the provided SVG data.
|
||||||
* @param {string} svgData - new SVG to use.
|
* @param {string} svgData - new SVG to use.
|
||||||
* @param {bool} [calculateRotationCenter=false] set the rotation center to the SVG center
|
* @param {number[]=} rotationCenter - Optional rotation center for the SVG. If not supplied, it will be
|
||||||
|
* calculated from the bounding box
|
||||||
*/
|
*/
|
||||||
setSVG (svgData, calculateRotationCenter) {
|
setSVG (svgData, rotationCenter) {
|
||||||
this._svgRenderer.fromString(svgData, () => {
|
this._svgRenderer.fromString(svgData, () => {
|
||||||
const gl = this._renderer.gl;
|
const gl = this._renderer.gl;
|
||||||
if (this._texture) {
|
if (this._texture) {
|
||||||
@ -72,7 +73,8 @@ class SVGSkin extends Skin {
|
|||||||
|
|
||||||
this._texture = twgl.createTexture(gl, textureOptions);
|
this._texture = twgl.createTexture(gl, textureOptions);
|
||||||
}
|
}
|
||||||
if (calculateRotationCenter) this.setRotationCenter.apply(this, this.calculateRotationCenter());
|
if (typeof rotationCenter === 'undefined') rotationCenter = this.calculateRotationCenter();
|
||||||
|
this.setRotationCenter.apply(this, rotationCenter);
|
||||||
this.emit(Skin.Events.WasAltered);
|
this.emit(Skin.Events.WasAltered);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user