界面如图 drawLine是画线的节点
//画线节点
private _drawLine: cc.Node = null;
//
private _point = [];
//用来确认是否有开始的节点(画线要有头才能画出尾)
private _lineNumber: number = 0;
//绘制的线段宽度
private _lineWidth: number = 12;
//
private _lastPoint = null;
private _initGame = () => {
//开启碰撞
Tools.getPhysics(true, false);
this._drawLine = this.getNode("drawLine");
this._drawLine.on(cc.Node.EventType.TOUCH_START, this._start);
this._drawLine.on(cc.Node.EventType.TOUCH_MOVE, this._move);
this._drawLine.on(cc.Node.EventType.TOUCH_END, this._end);
this._drawLine.on(cc.Node.EventType.TOUCH_CANCEL, this._end);
}
private _start = (event) => {
let local = event.getLocation(),
point = this._drawLine.convertToNodeSpaceAR(local);
if (this._handAABB(local)) {
this._point = [];
//进行结束的操作,为0没有线段
this._lineNumber++;
this._lastPoint = local;
//保存画线的位置
this._point.push(cc.v2(Tools.getInteger(point.x), Tools.getInteger