开发者

AS3: Graphics.lineStyle() -- Change ALPHA only?

In the method Graphics.lineStyle() you pass the alpha as the third parameter. I don't want to change the thickness or color which are the first 2 para开发者_JAVA技巧meters, so is there a way I can just change the alpha? or at least "get" the thickness and color so I can re-pass them so they wont change?

Thanks!!


One option would be to wrap the graphics object that you are passing around and add getters and setters for individual properties that are otherwise only available as parameters.

Pseudo-code:

public class CustomGraphics 
{
    // -- here is the wrapped graphics object
    protected var _graphics:Graphics;

    // -- unique properties for line style
    protected var _lineColor:uint;
    protected var _lineThickness:int;
    protected var _lineAlpha:Number;

    public function CustomGraphics( gfx:Graphics )
    {
          _graphics = gfx;
          _lineColor = 0;
          _lineThickness = 1;
          _lineAlpha = 1;

          draw();
    }

    public function set lineAlpha( value:Number ):void
    {
        if( _lineAlpha != value ) {
             _lineAlpha = value;
             // -- insert code to redraw or invalidate here
             draw();
        }
    }

    public function draw():void {
        _graphics.setLineStyle( _lineThickness, _lineColor, _lineAlpha );
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜