A function that's called when the user touches the screen and moves.
Declaring the function touchMoved() sets a code block to run automatically when the user touches a touchscreen device and moves:
function touchMoved() {
// Code to run.
}
The touches array will be updated with the most recent touch points when touchMoved() is called by p5.js:
function touchMoved() {
// Paint over the background.
background(200);
// Mark each touch point while the user moves.
for (let touch of touches) {
circle(touch.x, touch.y, 40);
}
}
The parameter, event, is optional. touchMoved() will be passed a TouchEvent object with properties that describe the touch event:
function touchMoved(event) {
// Code to run that uses the event.
console.log(event);
}
On touchscreen devices, mouseDragged() will run when the user’s touch points move if touchMoved() isn’t declared. If touchMoved() is declared, then touchMoved() will run when a user’s touch points move and mouseDragged() won’t.
Note: touchStarted(), touchEnded(), and touchMoved() are all related. touchStarted() runs as soon as the user touches a touchscreen device. touchEnded() runs as soon as the user ends a touch. touchMoved() runs repeatedly as the user moves any touch points.
उदाहरण
सिंटैक्स
touchMoved([event])
पैरामीटर्स
optional TouchEvent argument.