as3绘制更圆滑的圆角

时间:2014-08-04 11:40:06

标签: actionscript-3 graphics draw

我使用以下脚本绘制:

private function drawBkg():void {
    _bkg_shp.graphics.clear();
    _bkg_shp.graphics.lineStyle(1, 0x0, 1, false, LineScaleMode.NORMAL, CapsStyle.ROUND, JointStyle.ROUND);
    _bkg_shp.graphics.moveTo(_round, 0);
    _bkg_shp.graphics.lineTo(_width - _round, 0);
    _bkg_shp.graphics.curveTo(_width, 0, _width, _round);
    _bkg_shp.graphics.lineTo(_width, _height - _round);
    _bkg_shp.graphics.curveTo(_width, _height, _width - _round, _height);

    // draw down arrow
    const startPont:int = (_width + _arrowBase) * 0.5;

    _bkg_shp.graphics.lineTo(startPont, _height);
    _bkg_shp.graphics.lineTo(int(_width * 0.5), _height + _arrowHeight);
    _bkg_shp.graphics.lineTo(int(startPont - _arrowBase), _height);

    _bkg_shp.graphics.lineTo(_round, _height);
    _bkg_shp.graphics.curveTo(0, _height, 0, _height -_round);
    _bkg_shp.graphics.lineTo(0, _round);
    _bkg_shp.graphics.curveTo(0, 0, _round, 0);
}

结果是:

http://screencast.com/t/9bgcHV7sMW

有谁知道如何消除轮次的模糊性?捕捉到像素,取决于尺寸可以改善或恶化形状。

3 个答案:

答案 0 :(得分:2)

增加线条笔划粗细的厚度将有助于:

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);

答案 1 :(得分:-1)

避免线条问题的常见解决方案就是不使用它们:)

您只能通过填充绘制圆形矩形: 例如,该代码绘制了一个:

/**
 * Draw rectangle with rounded corners with fills (without lines) for 
 * nice scaling of corners
 */
public static function drawRoundRectAsFill (graphics:Graphics, 
                                            x:Number, y:Number, 
                                            w:Number, h:Number, 
                                            radius:Number,
                                            lineColor:uint=0x000000, fillColor:uint=0xffffff,
                                            lineThickness:Number=1,
                                            lineAlpha:Number=1, fillAlpha:Number=1):void
{
    graphics.lineStyle(0,0,0);
    graphics.beginFill(lineColor, lineAlpha);
    graphics.drawRoundRect(x, y, w, h, 2*radius, 2*radius);
    graphics.drawRoundRect(x+lineThickness, y+lineThickness, w-2*lineThickness, h-2*lineThickness, 2*radius-2*lineThickness, 2*radius-2*lineThickness);
    graphics.endFill();

    graphics.beginFill(fillColor,fillAlpha);
    graphics.drawRoundRect(x+lineThickness, y+lineThickness, w-2*lineThickness, h-2*lineThickness, 2*radius-2*lineThickness, 2*radius-2*lineThickness);
    graphics.endFill();
}                                           

答案 2 :(得分:-2)

为一切使用形状。不要使用线条。如初。