每当用户触摸屏幕时调用的函数。
每当用户开始触摸触屏设备时,声明一个名为 touchStarted() 的函数会设置一个代码块,自动运行:
function touchStarted() {
// Code to run.
}
当 p5.js 调用 touchStarted() 时,touches 数组将被更新为最新的触摸点:
function touchStarted() {
// Paint over the background.
background(200);
<p> // Mark each touch point once with a circle.
for (let touch of touches) {
circle(touch.x, touch.y, 40);
}
}
</p>参数 event 是可选的。touchStarted() 会被传递为一个描述触摸事件属性的 TouchEvent 对象:
function touchStarted(event) {
// Code to run that uses the event.
console.log(event);
}
在触屏设备上,如果未声明 touchStarted(),当用户触摸开始时,mousePressed() 会运行。如果声明了 touchStarted(),那么当用户触摸开始时将运行 touchStarted(),而 mousePressed() 不会运行。
注意:touchStarted()、touchEnded() 和 touchMoved() 都是相关的。touchStarted() 会在用户触摸触屏设备时立即运行。 touchEnded() 会在用户结束触摸时立即运行。touchMoved() 会在用户移动任何触摸点时重复运行。
示例
语法
touchStarted([event])
参数
event
TouchEvent:
可选的 TouchEvent 回调参数。
This page is generated from the comments in src/events/touch.js . Please feel free to edit it and submit a pull request!