A Solution to Reduce CPU/Memory Usage For Script-based Animation
As we could see, script-based animation always used a big amount of CPU/memory, which affects the performance definitely. So is there a solution to optimize but not trade-off?
I reviewed Algorithms in Java these days and making algorithm collections for Actionscript 3.0 version, while I’m working on a Flash project which required lots of manually information of paticular frames. Today I think I got a solution that to get improved for this problem in some way.
Like the improvement methods for algorithms, optimization for script-based animation we could get ideas from small cases of analysis, decreasing unnecessary loops, cuting unnecessary instruments inside important loops. But in this post I’m not want for those, but a method, that if a script-based movement is not totally random, save data down into scripts in some way .
Several months before there’s a Dr. Woohoo made something to take out information from AE for Flash integration, I don’t use any AE script so I don’t understand what is that exactly. But it lighted me to have an idea to record information details for animation, but not everything to calculate expensive sin() cos() atan2() with scripts in Flash. From my experience of current project, I run testing and record the information I need in a particular format, and trace out in the end. Then I copied them back directly into arrays in actionscript, in this way no more complex calculation required. So here is a brief of my solution:
1. Do everything in scripts.
2. Plan the data format to be used directly back with actionscript, such as positions, scale, rotation, in array, an so forth. What I say, a format of Actionscript ready for copy. If they will be mostly constant, it’s easy, if not, think about a simple algorithm or some functions to use constant input to get dynamic arrays (or linked-lists).
3. Put record code inside your functions, trace out them in the end.
4. Paste data back into your actionscript code. Testing and tuning.
5. Comment all unnecessary functions. Because for Flash SWF file, cut down unnecssary code means decreasing final size (think about the size of v2 components), that means another improvement for loading time.
It’s clear not everything we could do optimization in this way, but we can do some parts of these jobs, while leave impossible missions for scripts calculation. What we need is improvement not perfect. Surfers don’t care what you made your Flash, they just don’t want a higher CPU/memory load, they just prefer silent, quiet, and neat.
In fact, the Flash IDE itself has a similar manipulation for animation. You can use easing graph for animation of movieclips, while Flash IDE will save positions, rotation, scale data for each frame, no calcuation required so. But it only for animation of those kinds of, if you want to change some kinds of behavior of easing, or 3D, you can do nothing with Flash IDE, you have to plan to save those data in your own way for complex situation especially script-based animations.
























