LingDong- / q5xjs

A small and fast alternative (experimental) implementation of p5.js
https://q5xjs.netlify.app/
The Unlicense
548 stars 25 forks source link

fix: support touchStarted, touchEnded, touchMoved #24

Open psugihara opened 7 months ago

psugihara commented 7 months ago

fixes #22

Hey @LingDong- thanks for this awesome lib. Needed to get touch working for mobile and thought I'd share my solution back.

You use this by setting the handlers on q5:

const q5 = new Q5();
q5.touchStarted = () => {}
q5.touchMoved = () => {}
q5.touchEnded = () => {}
GoToLoop commented 7 months ago

$.touches = [...event.touches].map(getTouchInfo);

Isn't property touches an array already?!

psugihara commented 7 months ago

I think it's a TouchList which doesn't have .map in all implementations.

https://developer.mozilla.org/en-US/docs/Web/API/TouchList

GoToLoop commented 7 months ago

Oh, now I've got it why: $.touches = [...event.touches].map(getTouchInfo);

BtW, the old way to do that is: $.touches = Array.prototype.map.call(event.touches, getTouchInfo);

psugihara commented 7 months ago

Cool. That seems nice bc it doesn't create a new array.