as3.0中如何画两点间的虚线
4个回答
2013-01-24
展开全部
import flash.geom.Point;
/** * 画虚线
*
* @param graphics <b> Graphics</b>
* @param beginPoint <b> Point </b> 起始点坐标
* @param endPoint <b> Point </b> 终点坐标
* @param width <b> Number </b> 虚线的长度
* @param grap <b> Number </b> 虚线短线之间的间隔
*/
function drawDashed(graphics:Graphics, beginPoint:Point, endPoint:Point, width:Number, grap:Number):void
{
if (!graphics || !beginPoint || !endPoint || width <= 0 || grap <= 0) return;
var Ox:Number = beginPoint.x;
var Oy:Number = beginPoint.y;
var radian:Number = Math.atan2(endPoint.y - Oy, endPoint.x - Ox);
var totalLen:Number = Point.distance(beginPoint, endPoint);
var currLen:Number = 0;
var x:Number, y:Number;
while (currLen <= totalLen)
{
x = Ox + Math.cos(radian) * currLen;
y = Oy +Math.sin(radian) * currLen;
graphics.moveTo(x, y);
currLen += width;
if (currLen > totalLen) currLen = totalLen;
x = Ox + Math.cos(radian) * currLen;
y = Oy +Math.sin(radian) * currLen;
graphics.lineTo(x, y);
currLen += grap;
}
}
this.graphics.lineStyle(1,0xFF0000)
drawDashed(this.graphics, new Point(10,10), new Point(200,200), 15, 20)
/** * 画虚线
*
* @param graphics <b> Graphics</b>
* @param beginPoint <b> Point </b> 起始点坐标
* @param endPoint <b> Point </b> 终点坐标
* @param width <b> Number </b> 虚线的长度
* @param grap <b> Number </b> 虚线短线之间的间隔
*/
function drawDashed(graphics:Graphics, beginPoint:Point, endPoint:Point, width:Number, grap:Number):void
{
if (!graphics || !beginPoint || !endPoint || width <= 0 || grap <= 0) return;
var Ox:Number = beginPoint.x;
var Oy:Number = beginPoint.y;
var radian:Number = Math.atan2(endPoint.y - Oy, endPoint.x - Ox);
var totalLen:Number = Point.distance(beginPoint, endPoint);
var currLen:Number = 0;
var x:Number, y:Number;
while (currLen <= totalLen)
{
x = Ox + Math.cos(radian) * currLen;
y = Oy +Math.sin(radian) * currLen;
graphics.moveTo(x, y);
currLen += width;
if (currLen > totalLen) currLen = totalLen;
x = Ox + Math.cos(radian) * currLen;
y = Oy +Math.sin(radian) * currLen;
graphics.lineTo(x, y);
currLen += grap;
}
}
this.graphics.lineStyle(1,0xFF0000)
drawDashed(this.graphics, new Point(10,10), new Point(200,200), 15, 20)
展开全部
你可以使用画直线的API,把直线切成线段,一段一段地画。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
as3没有提供这样的API,自己写
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个需要自己写啦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询