简体   繁体   English

将过滤器应用于AS3中的所有内容

[英]Apply Filter to Everything in AS3

I'm trying to add a filter in AS3/Flex SDK. 我正在尝试在AS3 / Flex SDK中添加过滤器。 I can add a filter just fine to any one single object - but I want to apply the filter to everything that is a child of a certain object. 我可以添加一个过滤器就好了任何一个单一的对象-但我想过滤器适用于一定对象的孩子的一切

Think a pause window pops up, and everything below the pause window goes blurry. 认为弹出一个暂停窗口,并且暂停窗口下方的所有内容都变得模糊。

Applying a filter to each individual object (eg: iterating through a list) doesn't work, as the filters from each object can then overlap and look pretty ugly. 将过滤器应用于每个单独的对象(例如,遍历列表)不起作用,因为来自每个对象的过滤器可能会重叠并且看起来很丑陋。

Does anyone know how to go about doing this? 有人知道该怎么做吗? Is there a way to apply a filter to everything ? 有没有办法对所有内容应用过滤器?

Here's a simplified version of the code: 这是代码的简化版本:

myCanvas.graphics.beginFill(0x00FF00,0.5);
myCanvas.graphics.drawRect(0,0,100,100);
myCanvas.addChild(new vectorImage());
myCanvas.addChild(new vectorImage2());
var blur:BlurFilter = new BlurFilter();
myCanvas.filters = [blur];

Neither the directly-drawn graphics nor the children get the blur effect applied. 直接绘制的图形和子级都不会应用模糊效果。 I've tried altering the defaults and tried other filters: 我尝试过更改默认值,并尝试了其他过滤器:

var colors:Array = [0xEDEDED, 0xCCCCCC, 0x211b28, 0x211b28, 0x211b28];
var alphas:Array = [0, 1, .35, .5, 1];
var ratios:Array = [0, 50, 100, 115, 155];              
myCanvas.filters = [new GradientGlowFilter(0, 0, colors, alphas, ratios, 50, 50, 1, 3, "full", false)];

With identical effects (that is to say: none). 具有相同的效果(即:无)。 What DOES work, is: 起作用的是:

var vi:MovieClip = new vectorImage();
myCanvas.addChild(vi);
vi.filters = [blur];

but produces the above mentioned problems with multiple filters not aligning properly. 但由于多个滤镜未正确对齐而产生上述问题。

As I see it, you have two possible approaches: 如我所见,您有两种可能的方法:

  • put everthing you want to blur in a separate container as the rest and apply the filters to that container. 将您要模糊处理的所有内容放在其他容器中,然后将滤镜应用于该容器。

  • create a BitmapData of the size of the stage (or the part you want to blur), draw the stage, applyFilter, add it to the the display list (on top of everything) and on top of that add all sprites that shouldn't be blurred (I imagine an alert box or similar). 创建一个舞台大小(或您要模糊的部分)大小的BitmapData,绘制舞台,applyFilter,将其添加到显示列表中(在所有内容的顶部),并在其顶部添加所有不应包含的sprite模糊(我想是一个警告框或类似框)。 Note that you should update the BitmapData on resize. 请注意,您应该在调整大小时更新BitmapData。

UPDATE: Your code seems correct, but I'm not familiar with Flex, so maybe you can't add filters to Canvas (is it a DisplayObject?)... maybe setting his cacheAsBitmap to false works (it's quite buggy sometimes)... anyway, something like this should do the trick: 更新:您的代码似乎正确,但是我对Flex并不熟悉,所以也许您不能向Canvas添加过滤器(它是DisplayObject吗?)...也许将他的cacheAsBitmap设置为false(有时是很麻烦的)。 ..无论如何,这样的事情应该可以解决:

var container=new Sprite();
myCanvas.addChild(container);
container.addChild(new vectorImage());
container.addChild(new vectorImage2());
container.filters=[blur];

or maybe Canvas has a container property already... 也许Canvas已经具有容器属性...

Cheers... 干杯...

//in timeline code or Document class //在时间轴代码或Document类中

var blur:BitmapFilter = new BlurFilter(5, 5, BitmapFilterQuality.HIGH); var blur:BitmapFilter = new BlurFilter(5,5,BitmapFilterQuality.HIGH); var allFilters:Array = new Array(); var allFilters:Array = new Array(); allFilters.push(filter); allFilters.push(过滤器); filters = allFilers; 过滤器= allFilers;

You should be able to just apply your blur to the container. 您应该能够仅将模糊应用于容器。 The filters property is an array though. 虽然filter属性是一个数组。 Try something like this: 尝试这样的事情:

var blur:BlurFilter = new BlurFilter();
myCanvas.filters = [blur];

if i understand you question right, applying the filters to the stage would be the most simple thing, no? 如果我理解您的问题是对的,那么将滤镜应用于舞台将是最简单的事情,不是吗?

greetz 格尔茨

back2dos back2dos

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM