绘图三角形状背景

时间:2013-01-28 14:34:57

标签: actionscript-3

我在阵列中有三个点。我想用这个点绘制一个三角形。

现在,我实现使用MoveTo()和LineTo()函数绘制此三角形的边框。

问题是,我还需要绘制这条线创建的区域的内部背景。

有没有办法实现这个目标?

1 个答案:

答案 0 :(得分:4)

您应该使用graphics.beginFill(color);

public function astest()
{
    var verticies:Vector.<Point> = Vector.<Point>([new Point(0, 100), new Point(100, 0), new Point(100, 100)]);
    var sh:Shape = new Shape();
    addChild(sh);

    drawPolygon(sh.graphics, verticies, 0xFF0000);
}

protected function drawPolygon(graphics:Graphics, verticies:Vector.<Point>, color:uint):void
{
    graphics.beginFill(color);
    var p:Point = verticies.shift();
    graphics.moveTo(p.x, p.y);
    for(var i:int = 0; i < verticies.length; i++)
    {
        p = verticies[i];
        graphics.lineTo(p.x, p.y);
    }   
    graphics.endFill();
}
相关问题