2

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

问题是路径连接不准确。

结果是:

大喊

<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

4

2 回答 2

3

增加线条笔画粗细会有所帮助;同样,尝试指定 caps 和 joint:

大喊

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);
于 2013-06-17T00:33:33.970 回答
2

如果您指的是奇怪的抗锯齿,请尝试打开像素提示:

targetSprite.graphics.lineStyle(1.0, 0x000000, 1.0, true);
于 2013-06-16T20:09:49.003 回答