参考 touchEnded()

touchEnded()

每当屏幕触摸结束时调用的函数。

声明函数 touchEnded() 会设置一个代码块,在用户停止触摸触屏设备时自动运行:

function touchEnded() { // Code to run. }

当 p5.js 调用 touchEnded() 时,touches 数组将被更新为最新的触摸点:

function touchEnded() { // Paint over the background. background(200); <p> // Mark each remaining touch point when the user stops // a touch. for (let touch of touches) { circle(touch.x, touch.y, 40); } } </p>

参数 event 是可选的。touchEnded() 将被传递一个 TouchEvent 对象,该对象具有描述触摸事件的属性:

function touchEnded(event) { // Code to run that uses the event. console.log(event); }

在屏幕设备上,如果未声明 touchEnded(),当用户的触摸结束时,mouseReleased() 将运行。如果声明了 touchEnded(),那么当用户的触摸结束时将运行 touchEnded(),而 mouseReleased() 不会运行。

注意:touchStarted()touchEnded()touchMoved() 是相关的。当用户触摸屏幕设备时,touchStarted() 会立即运行。当用户结束触摸时,touchEnded() 会立即运行。当用户移动任何触摸点时,touchMoved() 会重复运行。

示例

语法

touchEnded([event])

参数

event

可选的 TouchEvent 回调参数。

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

相关参考