0

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

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

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

然后我需要“剪切”出精灵的一部分并将其用作不同精灵的蒙版。

问题是 - 当我剪掉 Sprite 时 - 我需要剪下的“边缘”不会模糊,

但是“BlurFilter”应用在“cut”Sprite 上,所以边缘是模糊的。

这是图片中的问题

图片中的问题 http://s11.postimage.org/820by8y29/Prblm_Mask2.png

我想到了一种解决方法,它有两个问题:

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

这种方法有两个问题:

  1. 业绩命中
  2. 不能让它工作...

有人能告诉我如何在不复制位图数据的情况下解决这个需求吗?

更新

这是我使用的代码片段:

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

0 回答 0