diff --git a/src/blocks/scratch3_event.js b/src/blocks/scratch3_event.js index ba496a17..631546a9 100644 --- a/src/blocks/scratch3_event.js +++ b/src/blocks/scratch3_event.js @@ -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,18 @@ class Scratch3EventBlocks { }; } + 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); + } + hatGreaterThanPredicate (args, util) { const option = Cast.toString(args.WHENGREATERTHANMENU).toLowerCase(); const value = Cast.toNumber(args.VALUE);