Skip to content

Commit f5ce73a

Browse files
authored
Merge pull request #2314 from adroitwhiz/dont-update-rotation-center
Remove calls to updateDrawableSkinIdRotationCenter
2 parents 3c5fa3a + c30fcd2 commit f5ce73a

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

src/import/load-costume.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,21 @@ const loadBitmap_ = function (costume, runtime, _rotationCenter) {
212212
return fetched;
213213
})
214214
.then(({canvas, mergeCanvas, rotationCenter}) => {
215-
// createBitmapSkin does the right thing if costume.bitmapResolution or rotationCenter are undefined...
216-
costume.skinId = runtime.renderer.createBitmapSkin(canvas, costume.bitmapResolution, rotationCenter);
215+
// createBitmapSkin does the right thing if costume.rotationCenter is undefined.
216+
// That will be the case if you upload a bitmap asset or create one by taking a photo.
217+
let center;
218+
if (rotationCenter) {
219+
// fetchBitmapCanvas will ensure that the costume's bitmap resolution is 2 and its rotation center is
220+
// scaled to match, so it's okay to always divide by 2.
221+
center = [
222+
rotationCenter[0] / 2,
223+
rotationCenter[1] / 2
224+
];
225+
}
226+
227+
// TODO: costume.bitmapResolution will always be 2 at this point because of fetchBitmapCanvas_, so we don't
228+
// need to pass it in here.
229+
costume.skinId = runtime.renderer.createBitmapSkin(canvas, costume.bitmapResolution, center);
217230
canvasPool.release(mergeCanvas);
218231
const renderSize = runtime.renderer.getSkinSize(costume.skinId);
219232
costume.size = [renderSize[0] * 2, renderSize[1] * 2]; // Actual size, since all bitmaps are resolution 2

src/sprites/rendered-target.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -458,19 +458,7 @@ class RenderedTarget extends Target {
458458
);
459459
if (this.renderer) {
460460
const costume = this.getCostumes()[this.currentCostume];
461-
if (
462-
typeof costume.rotationCenterX !== 'undefined' &&
463-
typeof costume.rotationCenterY !== 'undefined'
464-
) {
465-
const scale = costume.bitmapResolution || 2;
466-
const rotationCenter = [
467-
costume.rotationCenterX / scale,
468-
costume.rotationCenterY / scale
469-
];
470-
this.renderer.updateDrawableSkinIdRotationCenter(this.drawableID, costume.skinId, rotationCenter);
471-
} else {
472-
this.renderer.updateDrawableSkinId(this.drawableID, costume.skinId);
473-
}
461+
this.renderer.updateDrawableSkinId(this.drawableID, costume.skinId);
474462

475463
if (this.visible) {
476464
this.emit(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this);
@@ -709,11 +697,7 @@ class RenderedTarget extends Target {
709697
this.renderer.updateDrawableVisible(this.drawableID, this.visible);
710698

711699
const costume = this.getCostumes()[this.currentCostume];
712-
const bitmapResolution = costume.bitmapResolution || 2;
713-
this.renderer.updateDrawableSkinIdRotationCenter(this.drawableID, costume.skinId, [
714-
costume.rotationCenterX / bitmapResolution,
715-
costume.rotationCenterY / bitmapResolution
716-
]);
700+
this.renderer.updateDrawableSkinId(this.drawableID, costume.skinId);
717701

718702
for (const effectName in this.effects) {
719703
if (!this.effects.hasOwnProperty(effectName)) continue;

test/fixtures/fake-renderer.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ FakeRenderer.prototype.getFencedPositionOfDrawable = function (d, p) { // eslint
1717
FakeRenderer.prototype.updateDrawableSkinId = function (d, skinId) { // eslint-disable-line no-unused-vars
1818
};
1919

20-
FakeRenderer.prototype.updateDrawableSkinIdRotationCenter =
21-
function (d, skinId, rotationCenter) {}; // eslint-disable-line no-unused-vars
22-
2320
FakeRenderer.prototype.updateDrawablePosition = function (d, position) { // eslint-disable-line no-unused-vars
2421
this.x = position[0];
2522
this.y = position[1];

0 commit comments

Comments
 (0)