3 Replies Latest reply on Sep 19, 2011 11:28 AM by Ned Murphy

    Mouse direction problem (scroll)

    alaStickman Level 1

      hi,

      im making a shooting game and i want to have a little scroll for all the envirement when the mouse mouve .

      i did that but the problem is that when we keep moving the mouse on one direction it risk to get the envirement out of the scene .

      so what i want is to create a limite for this i don't want that my envirement stay moving while the mouse is moving so please if any one can fixe this i will appreciate that ^^.

      and i have a secondary problem :

      why the clips (MC1,MC2)don't move in the same speed for the same direction for example MC1 i want it to move 0.15 to the left and 0.15 to the right but he doesn't move in the same speed (sorry for my horrible english)

       

      thank you .

       

      CODE:

       

      speed1=0.15;

      speed2=0.10;

       

      //Scroll MC1

      checkMc1 = function (dx, oldVal, newVal) {

      if(oldVal<newVal){

      _root.mc1._x = (_root.mc1._x - speed1);

      }else if(oldVal>newVal){

      _root.mc1._x = (_root.mc1._x + speed1);

      }

      return newVal;

      };

       

      //Scroll MC2

      checkMc2=function(dx2, oldVal, newVal){

      if(oldVal<newVal){

      _root.mc2._x = (_root.mc2._x - speed2);

      }else if(oldVal>newVal){

      _root.mc2._x = (_root.mc2._x + speed2);

       

      }

      return newVal;

      }

      _root.watch("dir1",checkMc1);

      _root.watch("dir2",checkMc2);

      _root.onMouseMove=function(){

       

      dir1=_xmouse

      dir2=_xmouse

      }

        • 1. Re: Mouse direction problem (scroll)
          Ned Murphy Adobe Community Professional & MVP

          For the first issue you want to solve you need to build the conditions into your existing conditions or as separate enveloping conditions such that if moving MC1 or MC2 is going to move them outside of their limits, you prohibit the move...

           

          this is not actual code, just example...

           

          if(mc1._x - speed1 < mc1.lowerLimit && oldVal > newVal){

          mc1._x = mc1._x - speed1;

          } else ... etc...

           

          For the second issue, I doubt you will see a difference due to the size of the values

          1 person found this helpful
          • 2. Re: Mouse direction problem (scroll)
            alaStickman Level 1

            can you more explaine please .

            why you make (mc1._x - speed1)??

            i think that i only need the mc1 position so only (mc1._x)

            and what is mc.lowerLimit??

            and actually i try to did this :

            when mc1._x is = to limiteLeft then mc1 can't move to the left but it's possible to make him move to the right. same thing for the right and the other movie clips

            but  it always don't work this is what i did

             

            if((_root.mc1._x)=limitLeft){

            //i always put somethink wrong here can you help me please ?

                }

            • 3. Re: Mouse direction problem (scroll)
              Ned Murphy Adobe Community Professional & MVP

              I used mc1._x-speed because you used it.  Look at your own code.  I just removed the _root part of it because I suspect you are using it unnecessarily.  What my code does is check to see if making the change will make the object exceed the limit before you actually make the change... that prevents you from making the change and exceeding the limit

               

              For instance, suppose I do not want to exceed a limit...

               

              if(some._x < someLimit){

                  some._x += 10;

              }

               

              But what if that change ends up making some._x > someLimit and you don't want to exceed that limit?  Then what you need to do is test the change before you make it...

               

              // if making the change will still have it below the limit, make the change

              if(some._x +10 < someLimit){

                  some._x += 10;

              } else { // the object would jump beyond the limit, so just place it at the limit.

                  some._x = someLimit;

              }

               

              Also, for the code you just showed, you can't expect to get exactly the limitLeft value, so it is better to test if the change will make it less than (< or > ) the leftLimit.

               

              Also, when you test for equality you do not use "=". you use "=="

              1 person found this helpful