Flash AS:用Point简单制作虚线特效
http://www.itjxue.com 2015-07-17 23:38 来源:未知 点击次数:
Graphics为我们提供了moveTo/lineTo,drawRect等基本画图的方法...另外用lineStyle可以设置当中线的样式..可是当前还不支持虚线这种样式...其实我们可以用Point来简单的画出虚线的效果..先看看效果:
代码也很简单(只贴出主要的代码块):
- function drawDashed(graphics:Graphics,p1:Point,p2:Point,length:Number=5,gap:Number=5):void
- {
- var max:Number = Point.distance(p1,p2);
- var l:Number = 0;
- var p3:Point;
- var p4:Point;
- while(l<max)
- {
- p3 = Point.interpolate(p2,p1,l/max);
- l+=length;
- if(l>max)l=max
- p4 = Point.interpolate(p2,p1,l/max);
- graphics.moveTo(p3.x,p3.y)
- graphics.lineTo(p4.x,p4.y)
- l+=gap;
- }
- }