Make when clicked hats trigger on mouse down

This commit is contained in:
Paul Kaplan 2018-08-02 14:29:56 -04:00
parent de86eb3f19
commit ef50092daa

View file

@ -21,7 +21,7 @@ class Mouse {
* a drag end. * a drag end.
* @private * @private
*/ */
_activateClickHats (x, y, wasDragged) { _activateClickHats (x, y) {
if (this.runtime.renderer) { if (this.runtime.renderer) {
const drawableID = this.runtime.renderer.pick(x, y); const drawableID = this.runtime.renderer.pick(x, y);
for (let i = 0; i < this.runtime.targets.length; i++) { for (let i = 0; i < this.runtime.targets.length; i++) {
@ -29,18 +29,15 @@ class Mouse {
if (target.hasOwnProperty('drawableID') && if (target.hasOwnProperty('drawableID') &&
target.drawableID === drawableID) { target.drawableID === drawableID) {
// only activate click hat if the mouse up event wasn't // only activate click hat if the mouse up event wasn't
// the result of a drag ending // Activate both "this sprite clicked" and "stage clicked"
if (!wasDragged) { // They were separated into two opcodes for labeling,
// Activate both "this sprite clicked" and "stage clicked" // but should act the same way.
// They were separated into two opcodes for labeling, // Intentionally not checking isStage to make it work when sharing blocks.
// but should act the same way. // @todo the blocks should be converted from one to another when shared
// Intentionally not checking isStage to make it work when sharing blocks. this.runtime.startHats('event_whenthisspriteclicked',
// @todo the blocks should be converted from one to another when shared null, target);
this.runtime.startHats('event_whenthisspriteclicked', this.runtime.startHats('event_whenstageclicked',
null, target); null, target);
this.runtime.startHats('event_whenstageclicked',
null, target);
}
return; return;
} }
} }
@ -75,12 +72,14 @@ class Mouse {
); );
} }
if (typeof data.isDown !== 'undefined') { if (typeof data.isDown !== 'undefined') {
const previousDownState = this._isDown;
this._isDown = data.isDown; this._isDown = data.isDown;
const isNewMouseDown = !previousDownState && this._isDown;
// Make sure click is within the canvas bounds to activate click hats // Make sure click is within the canvas bounds to activate click hats
if (!this._isDown && if (isNewMouseDown &&
data.x > 0 && data.x < data.canvasWidth && data.x > 0 && data.x < data.canvasWidth &&
data.y > 0 && data.y < data.canvasHeight) { data.y > 0 && data.y < data.canvasHeight) {
this._activateClickHats(data.x, data.y, data.wasDragged); this._activateClickHats(data.x, data.y);
} }
} }
} }