TweenLite/TweenMax 支持卷积过滤器

TweenLite/TweenMax support for ConvolutionFilter

我正在使用如下方式将滤镜应用于位图:

TweenLite.to(origBitmap,0,{colorMatrixFilter:{saturation:2,brightness:3});

而且效果很好。

我需要以某种方式对 origBitmap 应用锐化过滤器,我已经使用 ConvolutionFilter 成功实现了这一点。问题是在我 运行 上面的 tweenlite 调用之后,然后创建一个卷积滤镜并将其应用于 origBitmap,它删除了初始饱和度和亮度滤镜,只保留锐化滤镜

private function applyEffects(effects:Array):void
{
  currentEffects = effects;
  var props:Object = {};
  for (var i:String in effects)
  {
    props[effects[i].effect] = effects[i].amount;
  }
  TweenLite.to(bitmap,0,{colorMatrixFilter:props});
  //-- props could look like {saturation:2,brightness:3}


  //-- This will sharpen the container sprite
  var matrix:Array = [0, -1,  0,
                     -1,  5, -1,
                      0, -1,  0];
  var conv:ConvolutionFilter = new ConvolutionFilter();
  conv.matrixX = 3;
  conv.matrixY = 3;
  conv.matrix = matrix;
  conv.divisor = 1; 
  bitmap.filters = [conv]; //-- this removes the above filters and just sharpens the image
}

有没有办法将 ConvolutionFilter 也合并到上面的 TweenLite 调用中?我搜索了很多,发现有人制作了一个名为 TweenMan 的 class,它基于你的 class,其中包含 ConvolutionFilter:https://github.com/danro/tweenman-as3

此处与 TweenMax 无关,因为您的代码是错误的。这正确地删除了所有当前过滤器并仅应用一个:

bitmap.filters = [conv];

因为过滤器 属性 为空或数组。要将过滤器添加到列表,您可以使用数组操作并重新应用数组:

var filters:Array = bitmap.filters;
if(!filters)
{
    filters = [];
}
filters.push(conv);
bitmap.filters = filters;

编辑:重新开始,因为我想我明白你想做什么。你正在避免自己创建过滤器,让 TwennLite 为你做,即使你不需要补间任何东西。不要那样做,你正在让自己的一切变得更难。而是以这种方式创建过滤器:

var props:Object = {};
var colorMatrix:ColorMatrixFilter = new ColorMatrixFilter();
for (var i:String in effects)
{
    colorMatrix[effects[i].effect] = effects[i].amount;
}
bitmap.filters = [colorMatrix];
//etc .... then
var filters:Array = bitmap.filters;
filters.push(conv);
bitmap.filters = filters;

如果您需要为多个滤镜制作动画,请记住大多数补间引擎可以轻松地对数组值进行补间,因此您只需这样做,然后将这些数组值应用于您的滤镜。