如何使用Agal在Stage3D中的位图上绘制一条线?

时间:2012-04-30 18:08:29

标签: actionscript stage3d agal

如何使用Agal在Stage3D中的位图上绘制一条线?有人可以提供代码示例吗?

2 个答案:

答案 0 :(得分:2)

如果你使用Starling,你可以试试这个:

/**
 * Class Line
 * @author Leandro Barreto 2012
 * @version 1.0
 **/

package starling.utils
{
    import starling.display.Quad;
    import starling.display.Sprite;

    public class Line extends Sprite
    {
        private var baseQuad:Quad;
        private var _thickness:Number = 1;
        private var _color:uint = 0x000000;

        public function Line()
        {
            baseQuad = new Quad(1, _thickness, _color);
            addChild(baseQuad);
        }

        public function lineTo(toX:int, toY:int):void
        {
            baseQuad.width = Math.round(Math.sqrt((toX*toX)+(toY*toY)));
            baseQuad.rotation = Math.atan2(toY, toX);
        }

        public function set thickness(t:Number):void
        {
            var currentRotation:Number = baseQuad.rotation;
            baseQuad.rotation = 0;
            baseQuad.height = _thickness = t;
            baseQuad.rotation = currentRotation;
        }

        public function get thickness():Number
        {
            return _thickness;
        }

        public function set color(c:uint):void
        {
            baseQuad.color = _color = c;
        }

        public function get color():uint
        {
            return _color;
        }
    }
}

有人在Starling论坛上建议我们创建一个Line类,它会绘制一些连接两个点的四边形。本教程介绍如何使用AGAL为着色器创建多边形:

http://wiki.starling-framework.org/manual/custom_display_objects

答案 1 :(得分:1)

我最近写了一个简单的库来在Stage3D上画线 它被称为Zebroid,https://github.com/luwes/Zebroid

Zebroid尚不支持线帽或关节。