9 Replies Latest reply on May 1, 2006 12:42 PM by Web_Maven

    Follow mouse exactly

    Web_Maven Level 1
      I have been working on this with no success. I want to follow the mouse but not like what is currently out there. I want to follow the mouse exactly. With the current follow mouse what happens is if your moving your mouse an you make a sharp turn the object following make a quick turn missing all the other mouse points. I was get to get this to work the way I wanted to a point.

      I was able to use an array for X & Y and call the array using a timer. Kind of like a object recorder but the problem I have is when you move the mouse fast the X & Y pos skips. So what I was trying to do is get the last X & Y in the array and subtract that from the previous X & Y in the array. If this number is larger then my object radius then add or subtract (add if going from L to R and subtract if going R to L) This is where I am having trouble. I like to figure things out on my own and would perfer ideas or samples before I resort to uploading the code. I have a counter the counter keeps track of where I am in the array but I think this is what is getting messed up.

      Also is it possible to create dynamic Arrays e.g. build arrays on the fly. var Xarray[MyVar]:Array = new Array(); the MyVar is what gets changed so I could have Xarray0, Xarray1, Xarray2...

      Any thoughts or if someone has samples thanks;
      Raymond
        • 1. Re: Follow mouse exactly
          Level 7
          > Also is it possible to create dynamic Arrays e.g. build arrays on the fly.
          > var Xarray:Array = new Array(); the MyVar is what gets changed so I could have
          > Xarray0, Xarray1, Xarray2...
          >
          > Any thoughts or if someone has samples thanks;
          > Raymond


          This is some code from the book Byte-Size Flash MX. It draws points on the stage as you move the mouse, saving the mouse points
          into an array. when you press a key it draws a line between all the points. Maybe the code could be of some use to you. The
          example has an empty stage and a 2 pixel round dot in the library with a linkage name of 'dot'
          I would add a limiter to avoid pushing too many points on the stack though. It might crash flash or your computer if you run for
          too long without clearing the stack.
          tralfaz

          points = [];
          onMouseMove = function ()
          {
          attachMovie("dot", "dot"+dotCount, dotCount++, {_x:_xmouse, _y:_ymouse});
          points.push(_xmouse, _ymouse);
          };

          function draw()
          {
          clear();
          i = 0;
          lineStyle(2, 0xff, 100); // thickness 2, blue, 100 alpha
          moveTo(points , points[i+1]);
          while ((i += 2)<points.length)
          {
          if (points
          == null)
          {
          i++;
          moveTo(points , points[i+1]);
          }
          else
          {
          lineTo(points
          , points[i+1]);
          }
          }
          }

          // press a key to draw the lines between the recorded dots
          Key.addListener(_root);
          _root.onKeyDown = function()
          {
          points.push(null);
          draw();
          };


          • 2. Re: Follow mouse exactly
            Web_Maven Level 1
            Thanks for the code, I did pick up some pointers from the code but I can't use the draw line. I am making it look like a marker and I want the draw line to have a ink bleed. You may be able to do it with the draw function I am not sure I know I can do it with the attach movie and animate the expansion.

            I want the effect as if you were in photoshop and you used the paint tool.

            Thanks
            • 3. Re: Follow mouse exactly
              Level 7
              "Web Maven" <webforumsuser@macromedia.com> wrote in message news:e33qss$mb$1@forums.macromedia.com...
              > Thanks for the code, I did pick up some pointers from the code but I can't use
              > the draw line. I am making it look like a marker and I want the draw line to
              > have a ink bleed. You may be able to do it with the draw function I am not
              > sure I know I can do it with the attach movie and animate the expansion.
              >
              > I want the effect as if you were in photoshop and you used the paint tool.
              >
              > Thanks

              I posted that code because you asked about recording mouse positions.
              tralfaz


              • 4. Re: Follow mouse exactly
                Web_Maven Level 1
                "tralfaz" I thank you for that.

                I am moving a movie clip, and the problem I am getting is that when you move the mouse fast you get a "Punch hole effect" so how do I tell the movie clip to animation between the "Punch hole"

                Sorry if there was confusion
                Raymond
                • 5. Re: Follow mouse exactly
                  Level 7
                  "Web Maven" <webforumsuser@macromedia.com> wrote in message news:e35ath$201$1@forums.macromedia.com...
                  > "tralfaz" I thank you for that.
                  >
                  > I am moving a movie clip, and the problem I am getting is that when you move
                  > the mouse fast you get a "Punch hole effect" so how do I tell the movie clip to
                  > animation between the "Punch hole"
                  >
                  > Sorry if there was confusion
                  > Raymond

                  We have the same problem with collision detection when the mouse is moved too quickly since the mouse points are too far apart. The
                  solution for collision detection is to check every point between the two recorded mouse points. You could do the same thing with
                  your movieclip movements.. move to all the points between the two, but only one move per frame.

                  tralfaz


                  • 6. Re: Follow mouse exactly
                    Web_Maven Level 1
                    I can see that collision detection would have the same problem. I was trying to do something like what you said. My object is 10px wide, so I check the last entry in the array (Pos1) and the one previous (Pos2). If the distance is greater then half the radius (5px) then I calculate how many I would need to fill the gap. I then add by 5px to the to Pos2 until I get to Pos1then put them all in to the array.

                    This brings up some questions, what if the mouse movement is curved. If I add numbers to the _x, _y position I would only be guessing at the position and the line would be diagonal and not curved? Dare I say is there some type of math I could use? (I have not mastered the Math functions yet)

                    Last question, if you use the draw functions to create a line is there a way to get the points from that line and use it as a guide? I know you can't use dynamic guide but if there was some way I could translate the line points into an array that would allow my movie clip to follow.

                    Thanks;
                    Raymond
                    • 7. Re: Follow mouse exactly
                      Web_Maven Level 1
                      The effect I am looking to do is simular to what they have here. I guess I could use the sothink software but that would be cheating and I would learn nothing.

                      http://www.crayola.com/colorexplosion/

                      Thanks again for any help.
                      • 8. Re: Follow mouse exactly
                        Level 7
                        "Web Maven" <webforumsuser@macromedia.com> wrote in message news:e35g8m$bp4$1@forums.macromedia.com...
                        > The effect I am looking to do is simular to what they have here. I guess I
                        > could use the sothink software but that would be cheating and I would learn
                        > nothing.
                        >
                        > http://www.crayola.com/colorexplosion/
                        >
                        > Thanks again for any help.

                        That one looks like a mask reveal rather than a duplication of points. When you do it that way you add bits to the mask to reveal
                        what is beneath it.
                        tralfaz


                        • 9. Re: Follow mouse exactly
                          Web_Maven Level 1
                          Yes but, you still get the punch hole effect if you move your mouse too fast (not on this site but when I do it) I have tried it two ways. The first was to use the Draw circle the circle revealed the mask the other way was to use a Movieclip so I could animate an ink spread I used the attachmoveclip function. Every time I was able to accomplish the same effect except I get the hole punch.

                          When you say you add bits what exactly do you mean?

                          Thanks for the help;
                          Raymond