当用户触摸屏幕并移动时调用的函数。
声明函数 touchMoved() 会设置一个代码块,当用户触摸屏幕并移动时调用的函数。
function touchMoved() {
// Code to run.
}
当 p5.js 调用 touchMoved() 时,touches 数组将被更新为最新的触摸点:
function touchMoved() {
// Paint over the background.
background(200);
<p> // Mark each touch point while the user moves.
for (let touch of touches) {
circle(touch.x, touch.y, 40);
}
}
</p>参数 event 是可选的。touchStarted() 会被传递为一个描述触摸事件属性的 TouchEvent 对象:
function touchMoved(event) {
// Code to run that uses the event.
console.log(event);
}
在屏幕设备上,如果未声明 touchMoved(),当用户的触摸点移动时,mouseDragged() 将运行。如果声明了 touchMoved(),那么当用户的触摸点移动时,将运行 touchMoved(),而 mouseDragged() 不会运行。
注意:touchStarted()、touchEnded() 和 touchMoved() 是相关的。当用户触摸触屏设备时,touchStarted() 会立即运行。当用户结束触摸时,touchEnded() 会立即运行。当用户移动任何触摸点时,touchMoved() 会重复运行。
示例
语法
touchMoved([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!