5 Replies Latest reply on Aug 2, 2006 6:09 AM by aniebel

    random wind and leaves

    aniebel Level 2
      Hi, I've found some grass items and some wind items around the forum and on google but these search words end up giving me other results. What I'm looking for is a tutorial on how to animate leaves as if wind is blowing by, intermittently. I did see, however, that this may bog down the Flash Player and I obviously don't want that. My thoughts are to create a movie clip of a leaf, duplicate it and have it respond to random code.

      When duplicating multiple movie clips, at what point (number of duplications) does the player start to bog down... 100... 1000? I'm not sure if there's a more efficient way to duplicate these clips and layer them so they don't all tween at once. I'd like it to occur as a wave. I'm going to try manually doing it to see.... duplicating and placing in other mcs so I can control the "holder" clips.

      I think this might be out of my reach with my AS2 abilities but I'd like to try anyway. Any suggestions helpful... thanks.
        • 1. Re: random wind and leaves
          jthereliable Level 1
          When duplicating multiple movie clips, at what point (number of duplications) does the player start to bog down... 100... 1000?
          #1 Depends on your computer, on mine, it can handle up to around 1000. I made fire before.
          #2 Why do you need 1000 leaves? As soon as the leaf leaves the screen, remove it.

          The code that would 100% remove it after it gets off the right side of the screen is:
          onEnterFrame=function()
          {
          if(_x>Stage.height+_width)
          {
          this.swapDepths(0)
          this.clear()
          this.removeMovieClip()
          }
          }

          Hope this helps.
          • 2. Re: random wind and leaves
            aniebel Level 2
            Thanks, it helps a bit. The leaves are not leaving (no pun intended) the screen. They remain on a stationary tree... it's the wind that "moves" across the screen. I know in 3D applications, one could use particles are something simliar to achieve natural controlled-chaos. I suppose it would take some time and experimentation to code something similar... and someone who knows what they are doing (unlike myself). ;-)
            • 3. Re: random wind and leaves
              jthereliable Level 1
              If you want it to leave on a tree, why not make it when wind comes in with a strength of X (maximum of 10, lets say)
              Make all the leaves turn (the leaves are initially facing down, so they are initially at 180 degrees)
              And then, make the tree bend a little and make the leaves

              _root.windStrength=random(11) //number between 0-10, including 0 and 10


              intialX=_x
              onEnterFrame=function()
              {
              _x+=_root.windStrength*3 //makes the leaf move 3*the wind strength, you can make it +random(10) to make it look more real
              _rotation+=(_rotation-(90+_root.windStrength*9))/5 //makes the wind rotate a towards 90 degrees when the wind is 10 and 100 when wind is 9, etc, etc. Makes it look like the wind is pushing it
              }


              The leaves stay on the tree, and you can make the wind come in every now and then.
              Hope this helps, if not, I'll be back xD!
              • 4. Re: random wind and leaves
                aniebel Level 2
                Cool, that will get me started. I am going to play around with what you suggested but in addition to that, I'm going to set it up so that the leaves on the left-hand side of the tree begin moving prior to the right... assuming the wind blows from left to right. But also, that random option is necessary so that it looks more realistic.

                Thanks, I'll post what I've come up with for review. Give me some time though as I'm fitting this project in as I have time for it. :-)
                • 5. Re: random wind and leaves
                  aniebel Level 2
                  Ok, I'm back after being sidetracked with other projects for awhile. I've started trying to work this out by doing a lot of research. This whole "learning to be a programmer" thing is tougher than I imagined yet somehow easier too. Anyway, I digress..

                  I may be traveling down the wrong path again but I am creating two classes now. One class for the wind and one for the leaf. Does this sound like the right direction? I am giving the wind class properties like speed, strength and the leaf class properties like rotation, position, size, etc.

                  By doing this, can't I create a function that generates (virtual) random wind bursts that effects the leaves as it "travels" across them? Or am I overthinking this issue like I'm so prone to do?

                  Thanks guys, I know I lean on you a lot for direction. It's the "thinking like a programmer" skill that I think I need to develop the most.