使用curveTo绘图

时间:2013-06-16 19:01:56

标签: actionscript-3 flex flex4

任务是使用curveTo图形方法绘制自定义形状。

问题是路径连接不准确。

结果是:

callout

<fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;

        protected function application1_creationCompleteHandler(event:FlexEvent):void
        {
            // TODO Auto-generated method stub

            test.graphics.clear();
            test.graphics.lineStyle(1);
            drawBorder(test.graphics, 200, 200);
        }

        private function drawBorder(g: Graphics, width: Number, height: Number): void
        {
            var cornerRadius: int = 20;
            var pointerWidth: int = 4;
            var pointerHeight: int = 10;
            var pointerBottomGap: int = 6;

            width -= pointerWidth;

            g.moveTo(0, height - cornerRadius);
            g.lineTo(0, cornerRadius + 1);
            g.curveTo(0, 0, cornerRadius, 0);
            g.lineTo(width - cornerRadius, 0);
            g.curveTo(width, 0, width, cornerRadius);
            var pointerY: int = height - pointerHeight - pointerBottomGap;
            g.lineTo(width, pointerY);
            g.lineTo(width + pointerWidth, pointerY + pointerHeight);
            g.lineTo(width - pointerWidth, pointerY + pointerHeight + 1);
            g.curveTo(width - pointerWidth, height, width - cornerRadius, height);
            g.lineTo(cornerRadius, height);
            g.curveTo(0, height, 0, height - cornerRadius);
        }

    ]]>
</fx:Script>

<mx:UIComponent 
    id="test"
    x="100" y="100"/>

问题可以改写 - 如何使用curveTo方法绘制角半径的矩形?

2 个答案:

答案 0 :(得分:3)

增加线行程重量的厚度将有所帮助;同样,尝试指定大写和联合:

callout

import flash.display.CapsStyle;
import flash.display.JointStyle;
import flash.display.LineScaleMode;

graphics.lineStyle(2,
                   0x0,
                   1.0,
                   true,
                   LineScaleMode.NORMAL,
                   CapsStyle.SQUARE,
                   JointStyle.MITER);

drawBorder(graphics, 200, 200);

答案 1 :(得分:2)

如果您指的是奇数抗锯齿,请尝试启用像素提示:

targetSprite.graphics.lineStyle(1.0, 0x000000, 1.0, true);