Moving touchingObject into rendered target

This commit is contained in:
Eric Rosenbaum 2018-06-06 16:34:58 -04:00
parent 431d4bd66b
commit 1a72512a62
3 changed files with 19 additions and 19 deletions

View file

@ -63,15 +63,7 @@ class Scratch3EventBlocks {
} }
touchingObject (args, util) { touchingObject (args, util) {
const requestedObject = args.TOUCHINGOBJECTMENU; return util.target.touchingObject(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);
} }
hatGreaterThanPredicate (args, util) { hatGreaterThanPredicate (args, util) {

View file

@ -150,16 +150,7 @@ class Scratch3SensingBlocks {
} }
touchingObject (args, util) { touchingObject (args, util) {
const requestedObject = args.TOUCHINGOBJECTMENU; return util.target.touchingObject(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);
} }
touchingColor (args, util) { touchingColor (args, util) {

View file

@ -724,6 +724,23 @@ class RenderedTarget extends Target {
return null; return null;
} }
/**
* Return whether 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.
*/
touchingObject (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. * Return whether touching a point.
* @param {number} x X coordinate of test point. * @param {number} x X coordinate of test point.