Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New extension: Touches #1608

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

DNin01
Copy link
Collaborator

@DNin01 DNin01 commented Jul 13, 2024

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:
Scratch blocks and Touches extension equivs side-by-side

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:
Touches extension block palette

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.

@CubesterYT
Copy link
Member

#1432 is a similar extension.

I like this PR though, matches category styling, and more, comprehensive blocks.

@Drago-Cuven
Copy link

something I must alert any "touch" based extension about, not every device with a touch screen is a mobile device. there are even windows 11 computers with touch screens. please keep this in mind when creating/editing extensions like this.

@DNin01
Copy link
Collaborator Author

DNin01 commented Jul 21, 2024

something I must alert any "touch" based extension about, not every device with a touch screen is a mobile device. there are even windows 11 computers with touch screens. please keep this in mind when creating/editing extensions like this.

Thanks.

The is touch screen? block was not intended to be a surefire method for projects to determine whether input is expected to always be in the form of touch. This would be worth pointing out if this extension ever gets documentation.

@GarboMuffin GarboMuffin added the pr: new extension Pull requests that add a new extension label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: new extension Pull requests that add a new extension
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants