From b726c4c18dc5032cd2827409cc21ee4f94636a01 Mon Sep 17 00:00:00 2001 From: sjhuang26 Date: Fri, 29 Dec 2017 08:31:59 -0500 Subject: [PATCH 1/3] Changed postSpriteInfo logic --- src/sprites/rendered-target.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index c41b967a3..13f9bd325 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -845,11 +845,10 @@ class RenderedTarget extends Target { */ postSpriteInfo (data) { const force = data.hasOwnProperty('force') ? data.force : null; - if (data.hasOwnProperty('x')) { - this.setXY(data.x, this.y, force); - } - if (data.hasOwnProperty('y')) { - this.setXY(this.x, data.y, force); + let isXChanged = data.hasOwnProperty('x'); + let isYChanged = data.hasOwnProperty('y'); + if (isXChanged || isYChanged) { + this.setXY(isXChanged ? data.x : this.x, isYChanged ? data.y : this.y, force); } if (data.hasOwnProperty('direction')) { this.setDirection(data.direction); From f7d80459c7cb693cbc442d99cb38f0e70f6f4ffa Mon Sep 17 00:00:00 2001 From: sjhuang26 Date: Fri, 29 Dec 2017 09:01:30 -0500 Subject: [PATCH 2/3] Fixed pen behavior when dragging --- src/extensions/scratch3_pen/index.js | 16 ++++++++++------ src/sprites/rendered-target.js | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/extensions/scratch3_pen/index.js b/src/extensions/scratch3_pen/index.js index abd46db12..c65400163 100644 --- a/src/extensions/scratch3_pen/index.js +++ b/src/extensions/scratch3_pen/index.js @@ -181,14 +181,18 @@ class Scratch3PenBlocks { * @param {RenderedTarget} target - the target which has moved. * @param {number} oldX - the previous X position. * @param {number} oldY - the previous Y position. + * @param {boolean} isForce - whether the movement was forced. * @private */ - _onTargetMoved (target, oldX, oldY) { - const penSkinId = this._getPenLayerID(); - if (penSkinId >= 0) { - const penState = this._getPenState(target); - this.runtime.renderer.penLine(penSkinId, penState.penAttributes, oldX, oldY, target.x, target.y); - this.runtime.requestRedraw(); + _onTargetMoved (target, oldX, oldY, isForce) { + // Only move the pen if the movement isn't forced (ie. dragged). + if (!isForce) { + const penSkinId = this._getPenLayerID(); + if (penSkinId >= 0) { + const penState = this._getPenState(target); + this.runtime.renderer.penLine(penSkinId, penState.penAttributes, oldX, oldY, target.x, target.y); + this.runtime.requestRedraw(); + } } } diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index 13f9bd325..fe9ede298 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -203,7 +203,7 @@ class RenderedTarget extends Target { this.x = x; this.y = y; } - this.emit(RenderedTarget.EVENT_TARGET_MOVED, this, oldX, oldY); + this.emit(RenderedTarget.EVENT_TARGET_MOVED, this, oldX, oldY, force); this.runtime.requestTargetsUpdate(this); } From 72dee72148d56d65d4d209b236638d8aa2f9a306 Mon Sep 17 00:00:00 2001 From: sjhuang26 Date: Fri, 29 Dec 2017 09:13:18 -0500 Subject: [PATCH 3/3] Change let to const --- src/sprites/rendered-target.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index fe9ede298..ee1109b5d 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -845,8 +845,8 @@ class RenderedTarget extends Target { */ postSpriteInfo (data) { const force = data.hasOwnProperty('force') ? data.force : null; - let isXChanged = data.hasOwnProperty('x'); - let isYChanged = data.hasOwnProperty('y'); + const isXChanged = data.hasOwnProperty('x'); + const isYChanged = data.hasOwnProperty('y'); if (isXChanged || isYChanged) { this.setXY(isXChanged ? data.x : this.x, isYChanged ? data.y : this.y, force); }