Reference touchEnded()

touchEnded()

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

event

optional TouchEvent argument.

Notice any errors or typos? Please let us know. Please feel free to edit src/events/touch.js and open a pull request!

Related References