extensions icon indicating copy to clipboard operation
extensions copied to clipboard

New extension: Touches

Open DNin01 opened this issue 1 year ago • 3 comments

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 both mouse and touch input events.

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
  • 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, 2. If the first finger is then lifted, its ID of 1 is freed up for the next touch.
  • 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, as if it were reassigned in-between two executions, code would just think the finger had moved. Subsequent touches that start on that same frame will instead be reassigned a new ID, which avoids problems like dragged objects jumping from one finger to another. However, this might mean that technically more than 10 touches can be "detected" at once, so just be aware that you might have touches with an ID greater 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.
  • If the user's device or browser doesn't support touch input, the (max touch points) block will return 1, because the mouse can still be used.

DNin01 avatar Jul 13 '24 20:07 DNin01

https://github.com/TurboWarp/extensions/pull/1432 is a similar extension.

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

CubesterYT avatar Jul 13 '24 21:07 CubesterYT

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.

Drago-Cuven avatar Jul 21 '24 03:07 Drago-Cuven

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 determining whether input is expected to always be in the form of touch. I'll be sure to point this out in a future documentation for this extension.

DNin01 avatar Jul 21 '24 18:07 DNin01