//windous 鼠标拖动绘制框
const { ccclass, property } = cc._decorator;
@ccclass
export default class drawNode extends cc.Component {
graphics : cc.Graphics = null;
touchStartPos : cc.Vec2 = null;
touchEndPos : cc.Vec2 = null;
onLoad() {
this.graphics = this.node.getComponent(cc.Graphics);
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
}
onTouchStart(EventTouch ){
this.graphics.clear()
let touch : cc.Touch = EventTouch.currentTouch;
this.touchStartPos = touch.getLocation();
}
onTouchMove(EventTouch){
let touch : cc.Touch = EventTouch.currentTouch;
let endPos = touch.getLocation()
this.drawRect(endPos)
}
onTouchEnd(){
this.graphics.clear()
}
onTouchCancel(){
this.touchStartPos = null;
this.touchEndPos = null;
this.graphics.clear()
}
drawRect(endPos : cc.Vec2){
this.touchEndPos = endPos;
this.graphics.clear()
this.graphics.rect(this.touchStartPos.x , this.touchStartPos.y , endPos.x - this.touchStartPos.x , endPos.y - this.touchStartPos.y )
this.graphics.stroke();
}
}