mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Make when clicked hats trigger on mouse down
This commit is contained in:
parent
de86eb3f19
commit
ef50092daa
1 changed files with 14 additions and 15 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue