mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Merge pull request #1214 from ericrosenbaum/feature/when-touching
Add when touching hat
This commit is contained in:
commit
173fb6127c
3 changed files with 27 additions and 10 deletions
|
@ -24,6 +24,7 @@ class Scratch3EventBlocks {
|
|||
*/
|
||||
getPrimitives () {
|
||||
return {
|
||||
event_whentouchingobject: this.touchingObject,
|
||||
event_broadcast: this.broadcast,
|
||||
event_broadcastandwait: this.broadcastAndWait,
|
||||
event_whengreaterthan: this.hatGreaterThanPredicate
|
||||
|
@ -41,6 +42,10 @@ class Scratch3EventBlocks {
|
|||
event_whenthisspriteclicked: {
|
||||
restartExistingThreads: true
|
||||
},
|
||||
event_whentouchingobject: {
|
||||
restartExistingThreads: false,
|
||||
edgeActivated: true
|
||||
},
|
||||
event_whenstageclicked: {
|
||||
restartExistingThreads: true
|
||||
},
|
||||
|
@ -57,6 +62,10 @@ class Scratch3EventBlocks {
|
|||
};
|
||||
}
|
||||
|
||||
touchingObject (args, util) {
|
||||
return util.target.isTouchingObject(args.TOUCHINGOBJECTMENU);
|
||||
}
|
||||
|
||||
hatGreaterThanPredicate (args, util) {
|
||||
const option = Cast.toString(args.WHENGREATERTHANMENU).toLowerCase();
|
||||
const value = Cast.toNumber(args.VALUE);
|
||||
|
|
|
@ -150,16 +150,7 @@ class Scratch3SensingBlocks {
|
|||
}
|
||||
|
||||
touchingObject (args, util) {
|
||||
const requestedObject = args.TOUCHINGOBJECTMENU;
|
||||
if (requestedObject === '_mouse_') {
|
||||
const mouseX = util.ioQuery('mouse', 'getClientX');
|
||||
const mouseY = util.ioQuery('mouse', 'getClientY');
|
||||
return util.target.isTouchingPoint(mouseX, mouseY);
|
||||
} else if (requestedObject === '_edge_') {
|
||||
return util.target.isTouchingEdge();
|
||||
}
|
||||
return util.target.isTouchingSprite(requestedObject);
|
||||
|
||||
return util.target.isTouchingObject(args.TOUCHINGOBJECTMENU);
|
||||
}
|
||||
|
||||
touchingColor (args, util) {
|
||||
|
|
|
@ -765,6 +765,23 @@ class RenderedTarget extends Target {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this target is touching the mouse, an edge, or a sprite.
|
||||
* @param {string} requestedObject an id for mouse or edge, or a sprite name.
|
||||
* @return {boolean} True if the sprite is touching the object.
|
||||
*/
|
||||
isTouchingObject (requestedObject) {
|
||||
if (requestedObject === '_mouse_') {
|
||||
if (!this.runtime.ioDevices.mouse) return false;
|
||||
const mouseX = this.runtime.ioDevices.mouse.getClientX();
|
||||
const mouseY = this.runtime.ioDevices.mouse.getClientY();
|
||||
return this.isTouchingPoint(mouseX, mouseY);
|
||||
} else if (requestedObject === '_edge_') {
|
||||
return this.isTouchingEdge();
|
||||
}
|
||||
return this.isTouchingSprite(requestedObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether touching a point.
|
||||
* @param {number} x X coordinate of test point.
|
||||
|
|
Loading…
Reference in a new issue