AS3 - 如何在更改颜色后在MovieClip上添加斜角过滤器

时间:2011-12-13 18:46:44

标签: actionscript-3 colors filter

当我用

改变颜色时
var blue:ColorTransform = new ColorTransform();
blue.color = 0xFF00B8E7;
MovieClip.transform.colorTransform = blue;

我添加了这个

var myBevel:BevelFilter = new BevelFilter();   
myBevel.type = BitmapFilterType.INNER;   
myBevel.distance = 3;   
myBevel.highlightColor = 0xFFFFFF;   
myBevel.shadowColor = 0x000000;   
myBevel.blurX = 5;    
myBevel.blurY = 5;  
MovieClip.filters = [myBevel];  

结果是,只有颜色改变了。

如何在我更改的新颜色之上或之上添加此斜角?

我到处看,发现我的问题没有答案 所以我希望你们能在这里帮助我! 似乎斜角将所有颜色都作为我改变的新颜色,而不是采用我指定的颜色

myBevel.highlightColor = 0xFFFFFF;   
myBevel.shadowColor = 0x000000;

2 个答案:

答案 0 :(得分:0)

尝试应用转换的顺序:

...;
myMovieClip.transform.colorTransform = blue;
...;
myMovieClip.filters = [myBevel];

VS

...;
myMovieClip.filters = [myBevel];
...;
myMovieClip.transform.colorTransform = blue;

斜角也可能提供自己的填充,无论你在做什么颜色转换。您可能希望尝试使用斜角的shadowAlphahighlightAlpha属性。将它们设置为0.1并查看您的影片剪辑是否为蓝色阴影。

答案 1 :(得分:0)

colorTransform将应用于整个动画片段,包括任何子项和过滤器。如果你尝试投影,你会看到我的意思。

方法#1: 您可以使用斜角过滤器创建父对象,并使用colorTransform附加您的movieclip。

    var parentObject:Sprite = new Sprite();
    addChild(parentObject);

    var mc:Sprite = new Sprite();
    mc.graphics.beginFill(0xFFFF00);
    mc.graphics.drawCircle(100,100, 100);
    mc.graphics.endFill();

    var blue:ColorTransform = new ColorTransform();
    blue.color = 0xFF00B8;

    var myBevel:BevelFilter = new BevelFilter();
    myBevel.type = BitmapFilterType.INNER;
    myBevel.distance = 3;
    myBevel.highlightColor = 0xFFFFFF;
    myBevel.shadowColor = 0x000000;
    myBevel.blurX = 5;
    myBevel.blurY = 5;

    parentObject.filters = [myBevel];
    parentObject.addChild(mc); 
    mc.transform.colorTransform = blue;

方法#2: 为了避免让父对象处理斜角,我使用了两个ColorMatrixFilters和一个AdjustColor来完成你想要的东西。您将最终得到3个滤镜,一个用于使对象变为白色,一个用于更改为您想要的颜色,以及最后一个斜角滤镜。如果您使用的是Flash以外的IDE,如Flex或FlashDevelop,则需要将flash.swc包含在库中,从“Common / Configuration / ActionScript 3.0 / libs / flash.swc”中为fl.motion.AdjustColor包/类。

    var mc:Sprite = new Sprite();
    mc.graphics.beginFill(0xFF0000);
    mc.graphics.drawCircle(100, 100, 100);
    mc.graphics.endFill();
    addChild(mc); 

    // White out the entire shape first
    var whiteAC:AdjustColor = new AdjustColor();
    whiteAC.brightness = 100;
    whiteAC.contrast = 100;
    whiteAC.saturation = -100;
    whiteAC.hue = 0;            
    var whiteMatrix:Array = whiteAC.CalculateFinalFlatArray();
    var whiteCMF:ColorMatrixFilter = new ColorMatrixFilter(whiteMatrix);

    // Now use ColorMatrixFilter to change color
    var colorMatrix:Array = hexToMatrix(0x0000FF);
    var colorCMF:ColorMatrixFilter = new ColorMatrixFilter(colorMatrix);

    // Create bevel
    var myBevel:BevelFilter = new BevelFilter();
    myBevel.type = BitmapFilterType.INNER;
    myBevel.distance = 3;
    myBevel.highlightColor = 0xFFFFFF;
    myBevel.shadowColor = 0x000000;
    myBevel.blurX = 5;
    myBevel.blurY = 5;

    mc.filters = [whiteCMF, colorCMF, myBevel];

    function hexToMatrix ( hex:uint, alpha:Number = 1 ) 
    {
        var r:Number = ((hex & 0xFF0000) >> 16);
        var g:Number = ((hex & 0x00FF00) >> 8);
        var b:Number = ((hex & 0x0000FF));

        var matrix:Array = [];
        matrix = matrix.concat([r, 0, 0, 0, 0]); // red
        matrix = matrix.concat([0, g, 0, 0, 0]); // green
        matrix = matrix.concat([0, 0, b, 0, 0]); // blue
        matrix = matrix.concat([0, 0, 0, alpha, 0]); // alpha
        return matrix;
    }