1 Reply Latest reply on Oct 23, 2006 11:59 PM by Jon_Moyles

    hitTests

    mpwalker
      I have a character on the stage with the following code:

      } onClipEvent (load) {
      _root.up=true
      _root.down=true
      _root.left=true
      _root.right=true
      }
      onClipEvent (enterFrame) {
      //Up movement
      if (Key.isDown(Key.UP)&&_root.up==true){
      gotoAndStop("moveback");
      this._y-=8;
      }
      //Down movement
      if (Key.isDown(Key.DOWN)&&_root.down==true){
      gotoAndStop("movefront");
      this._y += 8;
      }
      //Left movement
      if (Key.isDown(Key.LEFT)&&_root.left==true){
      gotoAndStop("moveleft");
      this._x -= 8;
      }
      //Right movement
      if (Key.isDown(Key.RIGHT)&&_root.right==true){
      gotoAndStop("moveright");
      this._x += 8;
      }


      walls with the following code:

      onClipEvent (enterFrame) {
      if (hitTest(_root.hero)) {
      _root.up = false;
      } else {
      _root.up = true;
      }
      }


      The problem is if I put in two or more walls with the same code (disabling the up variable for instance), only one of the walls will actually work. I know I should be able to figure this one out but it's driving me nuts. Any help and/or dunce cap would be graciously accepted. Thanks!
        • 1. Re: hitTests
          Jon_Moyles
          only the second wall to execute this code will work, since the first one to run it will have the relevant variable overwritten by the next object to run the code.

          you will need to do something like setting _root.up to true at the start of each 'refresh' of your screen then not setting it to true in your walls code.

          hth
          jon