AS3 - 如何'剪掉'一个带过滤器的Sprite部分?

时间:2012-11-04 10:40:58

标签: actionscript-3 flash filter

我使用'drawPath'绘制了一个Sprite。

然后我使用以下方法对此Sprite应用过滤器:

var myBlur:BlurFilter = new BlurFilter();
myBlur.blurX = 10;
myBlur.blurY = 10;
_alphaMask.filters = [myBlur];

然后我需要'剪掉'精灵的一部分并将其用作不同精灵的面具。

问题是 - 当我剪掉雪碧时 - 我需要剪切'边缘'不要模糊,

但'BlurFilter'应用于'cut'Sprite,因此边缘模糊。

以下是problem in pictures

problem in pictures http://s11.postimage.org/820by8y29/Prblm_Mask2.png

我想到了解决它的方法有两个问题:

将带有过滤器的Sprite中的BitmapData绘制到新的Sprite上, 然后在新的Sprite上使用'scrollRect'。

这种方法存在两个问题:

  1. Perfomance hit
  2. 无法让它工作......
  3. 有人能告诉我如何在不复制位图数据的情况下解决这个问题吗?

    更新

    以下是我使用的代码段:

    private var _alphaMask:Sprite;
    
    private createMask():void
    {
        _alphaMask = new Sprite();
        _alphaMask.visible = true;
    
        // Clear the mask
        _alphaMask.graphics.clear();
    
        // Create the mask vertices (the 'drawPath' coordinates)
        var maskPoints:Vector.<Number> = new Vector.<Number>(5);
        maskPoints.push(100);   maskPoints.push(100);
        maskPoints.push(200);   maskPoints.push(200);
        maskPoints.push(230);   maskPoints.push(310);
        maskPoints.push(140);   maskPoints.push(170);
        maskPoints.push(130);   maskPoints.push(190);
    
        // Create the 'drawPath' commands
        var commands:Vector.<int> = new Vector.<int>(commandLen);
        commands.push(1);
        commands.push(2);
        commands.push(2);
        commands.push(2);
        commands.push(2);
    
        // Draw the vertices on the mask
        _alphaMask.graphics.beginFill(0x0000FF);
        _alphaMask.graphics.drawPath(commands, clonedMaskPoints);
        _alphaMask.graphics.endFill();
    
            // Add the Blur filter to the mask
        var myBlur:BlurFilter   = new BlurFilter();
        myBlur.blurX            = myBlur.blurY = 10;
        _alphaMask.filters      = [myBlur];
    
    
    
        // Now I need to 'Cut Out' a section of the mask (and use it for something else...)
        // This section cuts out the part of the mask I need, but it 'reapplies' the blur filter on the entire cut mask
        var scrollRect_x:Number         = 100;
        var scrollRect_y:Number         = 100;
        var scrollRect_width:Number     = 300;
        var scrollRect_height:Number    = 200
        _alphaMask.scrollRect = new Rectangle(scrollRect_x, scrollRect_y, scrollRect_width, scrollRect_height);
    }
    

    这就是我试图解决问题的方法(没有成功):

    var alphaBitmapData:BitmapData = new BitmapData(_alphaMask.width, _alphaMask.height);
    alphaBitmapData.draw(_alphaMask);
    _alphaMask.graphics.clear();
    _alphaMask.graphics.beginBitmapFill(alphaBitmapData);
    _alphaMask.graphics.endFill();
    

0 个答案:

没有答案