3 Replies Latest reply on Aug 6, 2010 6:53 AM by kglad

    hittests for mcs inside other mcs

    Shad0wdrag0n Level 1

      I have a hittest code that's supposed to prevent an mc from moving into a space occupied by another mc. The thing is, the first mc is inside another mc and for some reason the hittest isn't registering. The code I'm using is below. Is it wrong somehow, or is there another code I should be using?

       

      Key.addListener(keyListener);

      this.onEnterFrame=loopF;

      function loopF() {

           if (border.hitTest(player.playerHit._x+(player.playerHit._width/2), player.playerHit._y, true)) {

              player._x -= speed;

          }

          if (border.hitTest(player.playerHit._x-(player.playerHit._width/2), player.playerHit._y, true)) {

              player._x += speed;

          }

          if (border.hitTest(player.playerHit._x, player.playerHit._y+(player.playerHit._height/2), true)) {

              player._y -= speed;

          }

          if (border.hitTest(player.playerHit._x, player.playerHit._y-(player.playerHit._height/2), true)) {

              player._y += speed;

          }

      }