games/Legend-of-the-Water-Cup/assets/scripts/TipLine.ts

56 lines
1.4 KiB
TypeScript

const {ccclass, property} = cc._decorator;
@ccclass
export default class TipLine extends cc.Component {
_points: cc.Vec2[];
draw:cc.Graphics;
onLoad()
{
this.draw=this.node.getComponent(cc.Graphics);
}
set points(v)
{
this._points=v;
this.draw.clear()
this.draw.moveTo(v[0].x,v[0].y)
for(var i=1;i<v.length;i++)
{
var startPos=v[i-1]
var endPos=v[i]
let line = endPos.sub(startPos);
let lineLenth = line.mag();
let unitLenth = 10;
let increment = line.normalize().mul(unitLenth);
let pos = startPos.clone();
var drawLine=true;
for(; lineLenth > unitLenth; lineLenth -= unitLenth){
if(drawLine){
this.draw.moveTo(pos.x, pos.y);
pos.addSelf(increment);
this.draw.lineTo(pos.x, pos.y);
this.draw.stroke();
}else{
pos.addSelf(increment);
}
drawLine = !drawLine;
}
if(drawLine){
this.draw.moveTo(pos.x, pos.y);
this.draw.lineTo(endPos.x, endPos.y);
this.draw.stroke();
}
}
this.draw.stroke();
}
get points()
{
return this._points;
}
// update (dt) {}
}