onTouchMoveCallback: function (event) {
let pos = this.node.convertToNodeSpaceAR(event.getLocation());
this.linePhysics.lineTo(pos.x, pos.y);
this.linePhysics.stroke();
this.linePhysics.moveTo(pos.x, pos.y);
// 记录当前手移动到的点
this.currentPos = cc.v2(pos.x, pos.y);
//求两点之间的距离
let subVec = this.currentPos.subSelf(this.recordPos);
let distance = subVec.mag() + 5;
// 如果距离大于一定值,这里的25是预制体的width
if (distance >= 25) {
// 给定方向向量
let tempVec = cc.v2(0, 10);
// 求两点的方向角度
let rotateVec = subVec.signAngle(tempVec) / Math.PI * 180 - 90;
// 创建预制体
let lineItem = cc.instantiate(this.linePrefab);
lineItem.rotation = rotateVec;
lineItem.parent = this.node;
Q1:为什么计算lineItem的旋转角度要用subVec 和tempVec 计算角度,而不用触摸点(pos 或 this.currentPos )计算?
Q2:为什么用subself而不用sub呢?