Posted on August 7, 2009 by Grant SkinnerI just filed a feature request for Flash player, asking for a cacheAsBitmapOptions property on display objects. The intent behind this is to make the current cacheAsBitmap functionality more useful. Currently, when you use cacheAsBitmap, the cache is redrawn any time you modify the transform the display object in any way other than translation (moving it in x/y). For example, if you rotate, alpha, or scale your display object it forces the cache to redraw. import flash.display.CacheAsBitmapOptions; // name based on NetStreamPlayOptions var myOpts:CacheAsBitmapOptions = new CacheAsBitmapOptions(); myOpts.updateOnRotation = false; myOpts.updateOnAlpha = false; myOpts.updateOnScale = false; myOpts.cacheScale = 2; characterSprite.cacheAsBitmapOptions = myOpts; // passing null would revert to defaults. otherSprite.cacheAsBitmapOptions = new CacheAsBitmapOptions(2, false, false, false); If you think this functionality would be useful for your projects, feel free to vote it up. The bug is filed in the Flash Player bugbase as bug #FP-2524.
Follow @gskinner on Twitter for more news and views on interactive media.
|
|
|
15 Comments
That's a good idea, i hope you will be listened by Adobe
Posted by: dafunker on Aug 7, 2009 4:22pm URL: http://dafunker.com
you got my vote. If adobe wants to improve there platform for games they should put there time in performance enhancements like this.
Posted by: iman khabazian on Aug 7, 2009 7:23pm URL: http://www.imanit.com
Flash could definitely do a better job caching with more information from programmers, like these settings.
I'm posting a related feature request, which is timeline caching. ( http://bugs.adobe.com/jira/browse/FP-2527 ) MovieClip timelines that are short and loop create and destroy lots of display objects in quick succession (making garbage), but these objects cannot be cached because MovieClip timelines can also take a long time to loop, or be set to never loop. A cacheTimeline property would let us specify whether the MovieClip should attempt to cache its timeline objects.
Posted by: Jeremy Sachs on Aug 8, 2009 5:18am URL: http://www.rezmason.net/blog
What is it that you're trying to accomplish? It is misguided to believe that the same performance benefits cacheAsBitmap achieves for translations will carry over to rotations and scaling.
The cacheAsBitmap feature is fast because it redraws a display object pixel for pixel on the screen, no calculations. When a bitmap is rotated or scaled those pixels have to be recalculated and anti-aliased into 'screen-pixels', which of course are always vertically and horizontally arrayed. In fact, the Flash Player's vector drawing processes are so fast that it's most often faster to let vectors recalculate and redraw when rotating or scaling than to rotate or scale a bitmap. In summary only the alpha would benefit from the extra option - your manual work and any efforts by Adobe to cache rotating and scaling display objects are less effective.
The real next step is to tie into hardware acceleration used for 3D graphics and allow 2D objects to receive full advantage.
Posted by: Tyler Wright on Aug 8, 2009 8:47am URL: http://www.xtyler.com
Hi Grant, yeah this is on my list too! I did actually write a superCacheAsBitmap class that did this ages ago - it even takes into account the multiple transformations of the clip's parents and readjusts the bitmap to fix. Matrix hell! I never properly converted it to AS3 but I'm sure it'd be quite easy. The main difficulty I had was trying to figure out what the API should be.
And embarrassingly, I don't think I ever got around to releasing the source... but more info about it here : http://www.sebleedelisle.com/?p=32
cheers!
Seb
Posted by: Seb Lee-Delisle on Aug 8, 2009 9:48am URL: http://sebleedelisle.com
Tyler - yes, this is correct for simpler vectors. However for more complex and/or deeply nested display structures, bitmap caching through transforms provides a significant performance benefit (obviously scaling with the complexity of the vectors). Text is a good example.
Posted by: Grant Skinner on Aug 8, 2009 3:11pm URL: http://gskinner.com/blog/
That's good idea for me.
I hope can see this at fp11 :)
Posted by: wooyaggo on Aug 9, 2009 1:11am URL: http://as3.kr
+1 Vote, and I can't wait to see your caching class.
Although when I created my caching class, I did it not just because of the update issue, but also because cacheAsBitmap = true forces pixelSnapping on for that display object, which looks very bad when an object is moving slowly. Could disabling that (seemingly pointless) binding be part of the new feature?
-Matt
Posted by: Matt Woomer on Aug 9, 2009 4:34pm
I would loved to have this feature. I wrote something similar too, to get the performance and behavior that I was looking for. My biggest concern was the transparency, not wanting every nested sprite to get transparent and intersecting eachother, but the complete cached bitmap as a solid object.
+1 Vote for me. =D
Posted by: Marcus Pettersson on Aug 10, 2009 1:38am URL: http://www.yooba.com
Don't forget to vote for gotoAndStop():
https://bugs.adobe.com/jira/browse/FP-901
which is also an important feature of Flash.
Posted by: gludion on Aug 10, 2009 3:49am
I do like the options idea, as it will automate the process, and work for timeline animations as well as programmatic tweens.
I'm not quite sure how the alpha flag would work - would it basically ignore alpha changes, or apply alpha changes to the cached bitmap?
A simpler solution might be to just being able to disable the redraw altogether, and re-enable it when a transition is done.
Most of the time, it's probably ok if not desired to completely 'freeze' the visual state, even if the content changes, during a transitional animation, then go back to the 'live' view. In essence that's what you do when you take that snapshot currently.
Posted by: Andreas Heim on Aug 12, 2009 5:28pm URL: http://www.smashingideas.com
I'd like to see more control over the bitmap caching as well. One other option you didn't mention is the ability to smooth the resulting bitmap. Without smoothing, using filters (which forces cacheAsBitmap) causes very jerky low quality motion (when scale and rotation not involved) at slow speeds because it snaps to pixels. Basically I want to see CacheAsBitmapOptions.smoothing.
https://bugs.adobe.com/jira/browse/FP-2539
Posted by: Aaron Beall on Aug 13, 2009 1:42pm URL: http://abeall.com
This is on my wishlist too. I would love to have this. My vote is in favor of this feature.
Posted by: Pankaj Negi on Aug 26, 2009 11:35pm
Is it monday, yet?
Posted by: Dan on Sep 25, 2009 7:39pm
Grant,
Can you not maintain a cached state through rotation by setting sprite.z = 0 ?
I know that is not a solution, but I believe it solves the rotation problem in flash 10...
Posted by: will on Nov 5, 2009 7:25pm URL: http://playauditorium.com