8 Replies Latest reply on Sep 16, 2006 8:40 AM by kglad

    CPU load

    aniebel Level 2
      Hi again. I'm back with another question on my neverending wind/tree project. I've got it all working which is good but I noticed that when the function runs, my CPU usage hits 100%. Is this just going to be what I have to live with or is there something I can do with the AS to trim it down and make it run leaner? I'm attaching the function. I've got about 100 leaves total and 10 mcs that contain around 10 leaves each. All leaves are instances of one mc which is very simple and tiny and one color. It rotates... that's it... no other tweens. I would like to get this to work more efficiently because I am keen on using this effect.
        • 1. Re: CPU load
          kglad Adobe Community Professional & MVP
          you probably are not going to benefit from enabling the cacheAsBitmap property of your leaves and parts because it looks like those movieclips are changing frames.

          that leaves you with 1440 operations and, depending upon how many of those hitTests resolve to true, up to 1440 tweens with EACH onEnterFrame loop. that's going to drain most cpus.
          • 2. Re: CPU load
            kglad Adobe Community Professional & MVP
            if you made a movieclip with say 10 leaves that rotate you could then have just 14 movieclips on stage and still have your 144 leaves and come close to having the same effect. that would result in much less cpu usage.
            • 3. Re: CPU load
              aniebel Level 2
              Yeah, I thought of making only 10 mcs also. This might be what I have to do but it has a less fluid appearance, obviously. I imagine I will have to experiment with several scenarios until I get what I'm looking for without the drain. I am unfamiliar with particles or any other method that might help to generate something more fluid. Basically, I'm trying to get it so show a ripple effect as the wind moves across the tree since wind doesn't always hit everything all at once unless there's a squall.

              Just thought I'd pick brains on possiblities of some other method to achieve this effect. But maybe Flash is not capable of a work-around for this yet. I am wondering if AS3 can handle something like this better???
              • 4. Re: CPU load
                kglad Adobe Community Professional & MVP
                i don't know of anything coming in flash 3 that would help in this situation.

                if you use a movieclip consisting of 10 leaves, the 10 leaves can each have different tweens/animations and they can all be clustered near one another.

                you can introduce a random element so each instance of this movieclip will have different leave motions (so, each cluster of leaves responds to the wind differently).

                the above should allow an effect similar to the one achieved with individual leaf animations with significantly reduced cpu drain.
                • 5. Re: CPU load
                  aniebel Level 2
                  I'll try that. So, even though there will still be 100 individual clips that are tweening, it's less stress on the CPU than detecting hittest? What about my situation is draining the CPU? Is it because of the onEnterFrame/hittest across so many mcs? Of course I don't really understand which processes add to the drain and which ones are reused.

                  I am considering getting rid of the hittest altogether. I only used it originally because I thought I could set a response across multiple clips and vary the "shape" of the wind to make it appear more natural without creating different tweens for each wind instance. Plus it seemed like a lot less work and, in the end, I think we all would like to achieve quicker results with code.

                  Thanks for helping me get to the bottom of this problem.
                  • 6. Re: CPU load
                    kglad Adobe Community Professional & MVP
                    no, you would not have 100 movieclips. you would have 10 movieclips each containing 10 leaves that you animate. if you're animating them using the actionscript tween class, that won't work (and is an additional source of cpu drain not apparent in the above code).

                    if you're animating the leaves using timeline tweens that above would decrease cpu utilization.
                    • 7. Re: CPU load
                      aniebel Level 2
                      Thanks, kglad!
                      • 8. Re: CPU load
                        kglad Adobe Community Professional & MVP
                        you're welcome.