1.切割直线
this.node.on(cc.Node.EventType.TOUCH_MOVE, (e) => {
this.draw.clear();
const startPoint = this.node.convertToNodeSpaceAR(e.getStartLocation());
this.draw.moveTo(startPoint.x, startPoint.y);
let pos = this.node.convertToNodeSpaceAR(e.getLocation());
this.draw.lineTo(pos.x, pos.y);
this.draw.stroke();
}, this);
this.node.on(cc.Node.EventType.TOUCH_END, (e) => {
this.draw.clear();
const p1 = e.getStartLocation();
const p2 = e.getLocation();
this.cut(p1, p2);//切割方法
}, this);
2.跟随手指画线
let self = this;
this.node.on(cc.Node.EventType.TOUCH_START, (e) => {
let pos = this.node.convertToNodeSpaceAR(e.getStartLocation());
self.draw.moveTo(pos.x, pos.y);
}, this)
this.node.on(cc.Node.EventType.TOUCH_MOVE, (e) => {
let pos2 = this.node.convertToNodeSpaceAR(e.getLocation());
self.draw.lineTo(pos2.x, pos2.y);
self.draw.stroke();
}, this);