7 Replies Latest reply on Aug 17, 2006 10:39 PM by leospit

    Movie Clip follow-mouse limit area

    leospit
      this is a follow mouse with elasticity code, works fine.
      the problem is about the limit area witch the movieclip can move or not
      in the bold area of the code, i can stop the mc but only in one axis,

      for ex:
      if(x_ziel > 608){ x_ziel = 608; }

      it stops following the mouse but only in the _x, it keeps moving the _y (i want both to stop)

      if my Movie Clip trespass my "_x" limit, id like to my MC stops also in the _y but with the coordinate that it was just before my mouse trespass it.


      onClipEvent (load) {
      vx = 0;
      vy = 0;
      x_wert = this._x;
      y_wert = this._y;
      x_ziel = this._x;
      y_ziel = this._y;
      elasticity = 1.6; //1.1, quanto maior menos elastico
      tempo = 10; //5, quanto maior menos rapido
      }
      onClipEvent (enterFrame) {
      x_wert = x_wert+vx;
      y_wert = y_wert+vy;
      vx = (vx+((x_ziel - 528 - x_wert)/tempo))/elasticity;
      vy = (vy+((y_ziel - 546 - y_wert)/tempo))/elasticity;
      this._x = x_wert;
      this._y = y_wert;
      }
      onClipEvent (mouseMove) {
      x_ziel = _root._xmouse;
      y_ziel = _root._ymouse;


      if(x_ziel > 608){
      x_ziel = 608;
      }
      if(x_ziel < 400){
      x_ziel = 400;
      }
      if(y_ziel > 611){
      y_ziel = 611;
      }
      if(y_ziel < 513){
      y_ziel = 513;
      }
      }


      anyone can help me?
        • 1. Movie Clip follow-mouse limit area
          Craig Grummitt Level 3
          i'm a little confused understanding exactly what your problem is - maybe because your code doesn't seem to work at all until the following two lines:

          vx = (vx+((x_ziel - 528 - x_wert)/tempo))/elasticity;
          vy = (vy+((y_ziel - 546 - y_wert)/tempo))/elasticity;

          become what they were in your previous post:

          vx = (vx+((x_ziel-x_wert)/tempo))/elasticity;
          vy = (vy+((y_ziel-y_wert)/tempo))/elasticity;

          once this problem is fixed, the movie clip seems to be limited in the x and y directions. isn't that what you're after?

          stop press - i think i see now that - 528 and - 546 were probably introduced into your code to adjust for registration points, but i guess i'm still confused about how you would like to improve the code.
          • 2. Movie Clip follow-mouse limit area
            leospit Level 1
            exactly, those are my adjustment for the movie clipe, witch is a pretty large mc

            my first language is not english =/ so it´s hard for me to explain it better
            but ill try =]

            is simple
            if u run this code u gonna see it has the limits, but, i wanted that movie clip to STOP whenever i get out of the limit, stop both _X and _Y at the same time

            for example, if my _xmouse is > than 608, the _x of the movie clip stops, BUT the _y continues following the _ymouse, that´s the problem, i also want the _y of my movie clip to stop following the _ymouse.

            it´s basically if i cross any of the limits, the mc will stop following mouse, in both_y and _x ways


            and craig, thanks A LOT for your attention and help
            i really apreciate it =]
            • 3. Re: Movie Clip follow-mouse limit area
              leospit Level 1
              can anyone help me? =|
              • 4. Re: Movie Clip follow-mouse limit area
                Craig Grummitt Level 3
                would you like it to stop abruptly? and start again when the user moves the mouse back within the limits?
                if so, does this do the trick?
                • 5. Re: Movie Clip follow-mouse limit area
                  leospit Level 1
                  hey craig, that´s pretty much what i want, but it´s stoping too abrupting, without the ease
                  is there some way to stop it with some ease?


                  and i was trying to put this code into the frame, not inte the MC, but it´s not working. i know im doing some stupidity though. heres the code


                  my_mc.onLoad = function () {
                  vx = 0;
                  vy = 0;
                  x_wert = my_mc._x;
                  y_wert = my_mc._y;
                  x_ziel = my_mc._x;
                  y_ziel = my_mc._y;
                  elasticity = 1.6; tempo = 10;
                  }
                  my_mc.onEnterFrame = function () {
                  x_wert = x_wert+vx;
                  y_wert = y_wert+vy;
                  vx = (vx+((x_ziel - 528 - x_wert)/tempo))/elasticity;
                  vy = (vy+((y_ziel - 546 - y_wert)/tempo))/elasticity;
                  my_mc._x = x_wert;
                  my_mc._y = y_wert;
                  }
                  my_mc.onMouseMove = function () {
                  x_ziel = _root._xmouse;
                  y_ziel = _root._ymouse;


                  if(x_ziel > 608){
                  x_ziel = 608;
                  }
                  if(x_ziel < 400){
                  x_ziel = 400;
                  }
                  if(y_ziel > 611){
                  y_ziel = 611;
                  }
                  if(y_ziel < 513){
                  y_ziel = 513;
                  }
                  }
                  • 6. Re: Movie Clip follow-mouse limit area
                    Craig Grummitt Level 3
                    as i say, its difficult to know exactly what you're after without sitting with you, as small changes in desired result can have significant differences in code, but anyway - take 2 - please see attached code for another attempt at what you're after...

                    the main problem with your code on the frame, by the way, was your use of onLoad. onLoad only works with movieclips connected to a class. you can actually only use onClipEvent(load) to run code when something on the stage is loaded... it's unnecessary anyway, because as soon as the code on that frame is processed the movieclip will have been loaded, so i just took that code out of the event handler. see livedocs
                    • 7. Re: Movie Clip follow-mouse limit area
                      leospit Level 1
                      craig, that´s perfect! it´s what i really wanted!!!

                      thank you SOOOOO MUCH
                      i really apreciate all the attention you had with me =]

                      i´m very used to put my codes (newbie codes lol) in frames so i never understood the onLoad function (and many others)
                      *now im starting to understand them

                      i work with design, and it´s tuff for me to also be a programer, i guess i will learn with time

                      once again, thanks a lot for your help =]