7 Replies Latest reply on May 14, 2009 7:46 AM by kglad

    Drawing API

    MJevons

      I am creating a car driving game in Flash 8. Im using the Drawing API to make the car leave tracks as it moves using the following method:

       

      lines = {}
      _root.createEmptyMovieClip("pen", 10)
      pen.lineStyle(10, 000000, 6)
      pen.moveTo(this.car._x, this.car._y)

       

      _root.onEnterFrame = function(){
             
              pen.lineTo(this.car._x, this.car._y)
              segments += 1
              name = "line"+segments
              lines[name] = [this.car._x, this.car._y]
      }

       


      A requirement of the game although is that the tracks fade after 2 - 3 car lengths and I was not sure if this was possible using the method I have already implemented.

       

      Any help would be much appriciated!

        • 1. Re: Drawing API
          kglad Adobe Community Professional & MVP

          to adjust the rate of fade, change the 2nd parameter in the setInterval() function and the 2nd parameter in setTimeout.  in fact, if you want a rapid fadeout, remove the setTimeout and just call startfadeF(pen):

           

           

          lines = {};
          var dep:Number = 0;
          this.car.prevX = this.car._x;
          this.car.prevY = this.car._y;

          _root.onEnterFrame = function() {
               var pen:MovieClip = _root.createEmptyMovieClip("pen"+dep,10+dep++);
              pen.lineStyle(10,000000,6);
               pen.moveTo(this.car.prevX,this.car.prevY);
               pen.lineTo(this.car._x,this.car._y);
               this.car.prevX = this.car._x;
               this.car.prevY = this.car._y;
               setTimeout(startfadeF,2000,pen);
              
               segments += 1;
               name = "line"+segments;
               lines[name] = [this.car._x, this.car._y];
          };
          function startfadeF(pen:MovieClip){
               pen.fadeI = setInterval(fadeF,50,pen);
          }
          function fadeF(pen:MovieClip){
               pen._alpha -= 3
               if(pen._alpha <= 0){
                    clearInterval(pen.fadeI);
          pen.removeMovieClip()
               }
               updateAfterEvent();
          }
          • 2. Re: Drawing API
            MJevons Level 1

            Thank you for your help kglad. I now have this working.

             

            I was although wondering if it was possible to have multiple lines drawn and then fade. I have managed to implement this using the method below to create duplicate movieclips of "pen" and reposition them although this slows the running of the flash movie significantly.

             

             

            var pen2:MovieClip = pen.duplicateMovieClip("pen2"+dep,10-dep++);
            pen2._x = pen._x - 28;
            pen2._y = pen._y - 28;
            setTimeout(startfadeF,2000,pen2);

             

             

             

             

            Do you know of any other way of doing this that might not slow the running of the flash movie?

             

            Cheers

            • 3. Re: Drawing API
              kglad Adobe Community Professional & MVP

              are you removing your movieclips when they've completed fade?

              • 4. Re: Drawing API
                Mattj0070

                I think I am. Im using:

                 

                clearInterval(pen.fadeI);pen.removeMovieClip()

                clearInterval(pen1.fadeI);pen1.removeMovieClip()

                clearInterval(pen2.fadeI);pen2.removeMovieClip()


                Although im not sure this is working as my CPU usage goes through the roof everytime I try and run the swf.

                • 5. Re: Drawing API
                  kglad Adobe Community Professional & MVP

                  that doesn't look right.

                   

                  if you're using the code i gave, you're removing the movieclips but that doens't look exactly like the code i gave.

                  • 6. Re: Drawing API
                    Mattj0070 Level 1

                    I have now set up exactly the code you gave me and it works. If I then try to increase the thickness of the line that is drawn from 1 to 20, this causes CPU usage to go up to 100% and the swf file starts running slow.

                     

                     

                     

                    The same applies if I create a duplicate movieclip of "pen".

                    • 7. Re: Drawing API
                      kglad Adobe Community Professional & MVP

                      the thickness is 10 in the code i gave, not 1.  show your problematic code.