A function that's called once each time a screen touch ends.
Declaring the function touchEnded()
sets a code block to run automatically when the user stops touching a touchscreen device:
function touchEnded() {
// Code to run.
}
The touches array will be updated with the most recent touch points when touchEnded()
is called by p5.js:
function touchEnded() {
// Paint over the background.
background(200);
// Mark each remaining touch point when the user stops
// a touch.
for (let touch of touches) {
circle(touch.x, touch.y, 40);
}
}
The parameter, event, is optional. touchEnded()
will be passed a TouchEvent object with properties that describe the touch event:
function touchEnded(event) {
// Code to run that uses the event.
console.log(event);
}
On touchscreen devices, mouseReleased() will run when the user’s touch ends if touchEnded()
isn’t declared. If touchEnded()
is declared, then touchEnded()
will run when a user’s touch ends and mouseReleased() 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.
Examples
Syntax
touchEnded([event])
Parameters
optional TouchEvent
argument.
Related References
touchEnded
A function that's called once each time a screen touch ends.
touchMoved
A function that's called when the user touches the screen and moves.
touchStarted
A function that's called once each time the user touches the screen.
touches
An Array of all the current touch points on a touchscreen device.