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

In the method, Graphics.lineStyle()you pass alpha as the third parameter. I do not want to change the thickness or color, which are the first two parameters, so that I can just change the alpha? or at least “get” thickness and color so that I can repeat them so they don't change?

Thank!!

+3
source share
1 answer

One option is to wrap the graphics object that you are going through 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 );
    }
}
+2
source

Source: https://habr.com/ru/post/1729103/


All Articles