PDA

View Full Version : Flex How to make filters scale relatively with parent DisplayObject ??



snowboardfoo
November 28th, 2009, 02:38 AM
AS3 Question for .filters

(i'm using flashdevelop / flex sdk)

IS there any way filters applied to a DisplayObject (drop shadow, glow, bevel) can scale relatively with the parent (the DisplayObject it is inside)?

And what about other properties like .distance for drop shadow?

For example...

If I have a 100px rectangle with a 10px glow inside a container object, and I set scaleX/scaleY of the container to .1, I want the glow to inherit the scale change from the parent (1/10th the size) just as the display object does that the filter is applied to.

Instead, if you try this, you will see the glow stays at 10px no matter what scale the filter target or the container is transformed by.

Pseudocode example (steps to reproduce),

1) create a sprite called _myOuterSprite on stage at scaleX = scaleY = 1

2) create a sprite called _myInnerSprite inside _myOuterSprite at scaleX = scaleY = 1

3) draw 100px rectangle into _myInnerSprite

4) apply 10px glow to _myInnerSprite

5) transform scale of _myOuterSprite to .1

Result:

- child sprite (rectangle) scales to 1/10th the size
- glow stays the same size

How can I make it so that glow scales to 1/10th as well?


http://www.actionscript.org/forums/images/smilies/confused.gif
...without capturing and scaling bitmap data
...without losing interactivity on objects
...in a way that would work visually for every filter, not just glow (drop shadow has distance property too, etc)

snowboardfoo
November 28th, 2009, 02:42 AM
i tried extending GlowFilter class but i get error:

Error: Base class is final.

snowboardfoo
November 28th, 2009, 06:28 PM
anyone have any tips?

wvxvw
November 29th, 2009, 04:14 AM
Scale the container of the object you applied the filter to?
Performance-wise filters scale good if set to, for example, for BlurFilter: 2, 4, 8 pixels blurriness. I.e. they use ConvolutionFilter mechanism when calculating the effect, which means they have a pixel matrix, like:
000
0X0
000
or
00000
00000
00X00
00000
00000
etc.

Where X is the pixel we calculate the effect for and 0's are the affected pixels. But if you set it to a value that doesn't translate into whole pixels, the calculation became at least twice more processor intensive.

snowboardfoo
November 29th, 2009, 05:37 PM
Scale the container of the object you applied the filter to?


That is exactly the problem- scaling the parent container of a child display object does scale the child display object (thru inheritance of matrix transforms as I understand it) but this does NOT effect the child display object's filters.

Not all properties should scale, either (some should scale, like blurX blurY, and some shouldn't, like color, strength, etc)

I've worked it out to calculate all parent scales and offset filter properties proportionally, but it seems to over compensate... I've settled on offsetting scale/2 and at least visually seems to give the desired effect...

Thanks for the tip on performance, it's a good point. I will round scale-changed properties to whole numbers... I did notice filter rendering starting to slow things down. Gracias! :ch:

Same topic on actionscript.org with a bit more content.. http://www.actionscript.org/forums/showthread.php3?p=946330