3 Replies Latest reply on Feb 8, 2007 8:42 AM by TroyK

    random stars emitting from a point

    xenolith5
      Hi, I'm V new to coding and need a little guidance. I don't want the code written for me just an outline of what I need to do for the following:
      I want to have a point on the stage where stars will emit from. The stars will have a bit of a wiggle!! and fade out after a set distance. Almost like a sparkler.
      I think I need to create a mc of the star with an instance name then use attachmovie to place it on the screen at a set point from the library. I think I then need to create an onEnterFrame function which uses Math.round to create a point for the star to fly to.
      If the star mc had a wiggly motion path and a tweened alpha then in my head this would cause the star to fly to the random point wiggling as it goes and fade out.
      Then I need to repeatedly call this function. If I then place multiple instances of this mc on the stage, each instance should move in random directions.
      So anyone who wants to give a brief outline for me to play with is a star!!
        • 1. Re: random stars emitting from a point
          TroyK
          Well i attached some code that should get you started. The stars only go in 4 different directions and they don't fade when they die or wiggle on the way. But maybe it will get you started with what you want.

          Later

          Troy
          • 2. Re: random stars emitting from a point
            xenolith5 Level 1
            Sorry for not thanking you, I've been away! Where you've used random(number) can I use Math.random()*number ? Could you also explain what's happening in the switch...case:
            star._y++;
            distance = star._y;
            distance = distance-startY;
            Thanks
            • 3. Re: random stars emitting from a point
              TroyK Level 1
              First, the function holding the switch case "moveStar" gets called on every frame for every star. Because of this line: star.onEnterFrame = moveStar

              So when a star enters a frame we want to move the star. And we need to know which direction to move it so I use the switch on star.direction. For example of star.direction = 0 then:

              //Down
              star._y++;
              this line moves the star down 1

              distance = star._y;
              distance = distance-startY;
              these two lines tell us how far the star has moved
              we use this info later in the function with:

              if (distance>star.lifespan) {
              killStar(star);
              }
              if the star has traveled farther than the lifespan we gave it then we remove the star.

              I hope this helps.

              Troy