views:

73

answers:

2

Hi,

I have say 10 items in a particular space, If I apply glows and drop shadows to all of them and all of these items are usually static. Other characters do move around them too. So I'm just wondering would it be wise to use vectors with actionscript blurs and glows. Or to have a PNG? and if I cannot have a PNG and have to work with vectors with glows/blurs/shadows. Would they be too heavy on the processor?

A: 

Lot's of PNG's with effects (i.e. blurs, glows, shadows, etc) baked into them will almost always outperform lot's of vector objects with the same effects applied via code. If you can't use PNG's then you can always take advantage of a little trick... BitmapData.applyFilter()! This method is awesome and I've managed to find significant performance increases under the very same circumstances you describe. Instead of using vector graphics I'll take a bitmap snapshot of the vector object like so:

var vectorGraphic:MovieClip = someVectorObectThatNeedsFiltersAppliedToIt;
var bmd:BitmapData = new BitmapData(vectorGraphic.width, vectorGraphic.height, true, 0x000000);
var glow:GlowFilter = new GlowFilter(0x00ffff, 1, 4, 4, 2, 1, false, false);
bmd.draw(vectorGraphic, null, null, null, null, true);
bmd.applyFilter(bmd, new Rectangle(0, 0, bmd.width, bmd.height), new Point(0, 0), glow);
var bmp:Bitmap = new Bitmap(bmd, 'never', true);

Good luck!

heavilyinvolved
Doesn't 'cacheAsBitmap' do exactly the same thing, without all the code you displayed?
amn
+1  A: 

When you apply a bitmap filter (glow, shadow, etc.) to any content, Flash automatically turns on a feature called Bitmap Caching. As long as that feature is on, Flash renders the object as a bitmap, and then will use that bitmap in place of the object until it decides it needs to re-render the object. Flash will re-render the object any time the object's internals (i.e. children) change in any way, or if the object itself undergoes any kind of transformation besides simple translation (changes in x/y).

What this means is:

  1. If your object doesn't change internally, and it doesn't rotate or change scale, then once you apply a filter it doesn't matter whether the object contains bitmaps or vectors. Internally Flash has cached it to a bitmap, so it will perform very well regardless of what's inside.
  2. If the object changes internally, or rotates or scales, then Flash will re-render the object every frame even with filters applied. In this case, having bitmaps inside the object will perform better than having complex vectors (including non-device text).
  3. If possible, it's better to apply filters to child objects which would not need to be frequently re-rendered, rather than applying them to a parent object which would.
fenomas
Thank you so much for the detailed answer, that would help a lot. If I import the vector from a AI file along with glow. how would that effect the processing and well one last question. If the vectors have a lot of gradients?
Fahim Akhter
I'm not sure what happens when you copy in things with filters from illustrator, but it will either come in as content with a filter, or as a bitmap of what the content looks like with a filter. If it's the former, it will be possible to change the filter in Flash after importing. Either way, and regardless of gradients, my answer applies - gradients make the content slower to render, but if you use Bitmap Caching is on and the object doesn't need to be redrawn, then it only gets rendered once.
fenomas