From d51a2ad39fbbc648a0e5a50840e4afff1df284de Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Wed, 28 Feb 2018 16:45:26 -0500 Subject: [PATCH] Use wasDragged flag to selectively activate 'when this sprite clicked' block on mouse up. --- src/io/mouse.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/io/mouse.js b/src/io/mouse.js index ecff2db10..eef3c4c86 100644 --- a/src/io/mouse.js +++ b/src/io/mouse.js @@ -17,17 +17,23 @@ class Mouse { * Activate "event_whenthisspriteclicked" hats if needed. * @param {number} x X position to be sent to the renderer. * @param {number} y Y position to be sent to the renderer. + * @param {?bool} wasDragged Whether the click event was the result of + * a drag end. * @private */ - _activateClickHats (x, y) { + _activateClickHats (x, y, wasDragged) { if (this.runtime.renderer) { const drawableID = this.runtime.renderer.pick(x, y); for (let i = 0; i < this.runtime.targets.length; i++) { const target = this.runtime.targets[i]; if (target.hasOwnProperty('drawableID') && target.drawableID === drawableID) { - this.runtime.startHats('event_whenthisspriteclicked', - null, target); + // only activate click hat if the mouse up event wasn't + // the result of a drag ending + if (!wasDragged) { + this.runtime.startHats('event_whenthisspriteclicked', + null, target); + } return; } } @@ -58,7 +64,7 @@ class Mouse { if (typeof data.isDown !== 'undefined') { this._isDown = data.isDown; if (!this._isDown) { - this._activateClickHats(data.x, data.y); + this._activateClickHats(data.x, data.y, data.wasDragged); } } }