测试代码
const { ccclass, property } = cc._decorator;
@ccclass
export default class Test extends cc.Component {
private Mask: cc.Graphics = null;
private line_point: cc.Vec2[] = [];
onLoad(): void {
this.Mask = this.node.getComponent(cc.Graphics);
this.Mask.lineWidth = 20;
this.Mask.strokeColor = new cc.Color().fromHEX("#f2a8a8");
this.Mask.fillColor = new cc.Color().fromHEX("#f2a8a8");
}
start(): void {
this.node.on(cc.Node.EventType.TOUCH_START, this.touch_start, this)
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touch_move, this)
this.node.on(cc.Node.EventType.TOUCH_END, this.touch_end, this)
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touch_end, this)
}
touch_start(event) {
let pos = this.node.convertToNodeSpaceAR(event.getLocation());
this.Mask.moveTo(pos.x, pos.y);
this.line_point.push(cc.v2(pos.x, pos.y));
}
touch_move(event) {
let pos = this.node.convertToNodeSpaceAR(event.getLocation());
this.Mask.lineTo(pos.x, pos.y);
this.line_point.push(cc.v2(pos.x, pos.y));
this.Mask.stroke();
}
touch_end(event) {
}
}