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开发者_Go百科 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?
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:
- 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.
- 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).
- 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.
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!
精彩评论