Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This may not be final yet, but I've been wanting to share it for a little while. It's a multi-touch extension.
Here's a picture that shows the Scratch versus Touches extension equivalents to a few scripts:
For this extension, I tried to add blocks that reduce the amount of coding you need to do to implement multi-touch. Here are all of them:
That creates some repetition and adds to the learning curve, but means you don't have to do everything yourself, and I also made a sample project to go with it. You can download and try it or watch the video. My plan is to publish the sample project via a separate PR if and once this PR is merged.
This extension uses the Pointer events web API, so it accepts all types of pointer input events, including mouse, touch, and even pen input. I have tested it on Chromium on desktop and mobile, plus Safari on mobile.
In a way, this extension is a superset of Scratch's mouse and click sensing blocks. They both work very similarly, it's just that one can deal with multiple pointers at a time.
Technical notes
Pointer IDs
When a finger touches the screen, it is assigned a unique numerical ID. Touch IDs start at 1 and each new touch will get an ID that isn't assigned to an active touch.
For example, if two fingers touch the screen one after another (or at the same time), one will have an ID of 1, and the other, an ID of 2. If the first finger is then lifted, its "slot" of ID 1 is freed up for the next touch.
Ghost slots
When a finger is released, the ID of its touch is actually reserved for one extra frame. This gives code time to respond to that touch being released; if a new touch was assigned an ID of a touch that had just been released, code would just think the finger had moved.
Instead, these touches will be assigned a different ID, which prevents problems like dragged objects jumping from one finger to another. However, this means you might have touches with an ID greater than the number of current or maximum active touches (e.g. more than 10). These reserved IDs, however, don't count to the total number of current active touches, and aren't considered to be "pressing" anything.
Non-touch devices
If the user's device or browser doesn't support touch input, the
(max touch points)
block will return 1, because the mouse is a pointer.