3 Replies Latest reply on Oct 22, 2011 10:30 AM by kglad

    Help..... Its attaching to the centre!!!!!!

    LukeElChul

      well im making a game like asteroids so far everything is working. then i decided to make a wall and create a script to make that wall fall down when hit by a roket that works also when it gets hit by a bullet. the problam is that the roket explotion and the bullet decal attach to the centre of the wall, when i want them to attach to where ever the Bullet/Roket Hits.

       

      heres my script.

       

       

       

      onClipEvent(load){

      var broken:Boolean = false

      }

       

      onClipEvent(enterFrame){

      for(i=0;i<_root.RoketArray.length;i++){

      if(this.hitTest(_root.RoketArray[i])){

      if(broken == false){

      removeMovieClip(_root.RoketArray[i])

      attachMovie("Explosion1","E",_root.getNextHighestDepth(),{_x:Roket._x,_y:Roket._y})

      gotoAndPlay(2);

      broken = true;

       

      }else if

      (broken == true)

      gotoAndStop(14);

      broken = true;

      }

      }

      }

       

      onClipEvent(enterFrame){

      for(i=0;i<_root.bulletArray.length;i++){

      if(this.hitTest(_root.bulletArray[i])){

      removeMovieClip(_root.bulletArray[i])

      attachMovie("BulletDecal","BD",_root.getNextHighestDepth(),{_x:Bullet._x,_y:Bullet._y})

      }

      }

      }

       

      thanks in advance (:

        • 1. Re: Help..... Its attaching to the centre!!!!!!
          kglad Adobe Community Professional & MVP

          you probably want:

           

           

           

           

           

          onClipEvent(load){

          var broken:Boolean = false

          }

           

          onClipEvent(enterFrame){

          for(i=_root.RoketArray.length-1;i>=0;i--){

          if(this.hitTest(_root.RoketArray[i])){

          if(broken == false){

          var mc:MovieClip=_root.RoketArray[i];

          mc._parent.attachMovie("Explosion1","E",_root.getNextHighestDepth(),{_x:mc._x, _y:mc._y})

          _root.RoketArray.splice(i,1);

          mc._parent.removeMovieClip(mc)


          gotoAndPlay(2);

          broken = true;

           

          }else if

          (broken == true)

          gotoAndStop(14);

          broken = true;

          }

          }

          }

           

          onClipEvent(enterFrame){

          for(i=root.bulletArray.length-1;i>=0;i--){

          if(this.hitTest(_root.bulletArray[i])){

          var mc:MovieClip=_root.bulletArray[i];

          mc._parent.attachMovie("BulletDecal","BD",_root.getNextHighestDepth(),{_x:mc. _x,_y:mc._y})

          _root.bulletArray.splice(i,1);

          mc._parent.removeMovieClip(mc);

           

          }

          }

          }

           

          • 2. Re: Help..... Its attaching to the centre!!!!!!
            LukeElChul Level 1

            thanks. your the best (:

             

            it had errors so i worked it out intill i got this.

             

             

             

             

            onClipEvent(load){

            var broken:Boolean = false

            }

             

            onClipEvent(enterFrame){

            for(i=_root.RoketArray.length-1;i>=0;i--){

            if(this.hitTest(_root.RoketArray[i])){

            if(broken == false){

            var mc:MovieClip=_root.RoketArray[i];

            mc._parent.attachMovie("Explosion1","E",_root.getNextHighestDepth(),{_x:mc._x,_y:mc._y})

            gotoAndPlay(2);

            broken = true;

            _root.RoketArray.splice(i,1);

            mc._parent.removeMovieClip(mc)

             

            }else if

            (broken == true)

            gotoAndStop(14);

            broken = true;

            }

            }

            }

            onClipEvent(enterFrame){

            for(i=0;i<_root.bulletArray.length;i++){

            if(this.hitTest(_root.bulletArray[i])){

            var mc:MovieClip=_root.bulletArray[i];

            mc._parent.attachMovie("BulletDecal","BD",_root.getNextHighestDepth(),{_x:mc._x,_y:mc._y} )

            _root.bulletArray.splice(i,1);

            mc._parent.removeMovieClip(mc);

            }

            }

            }

             

            THANKS!!!!!!!!!!!!!!!!!

            • 3. Re: Help..... Its attaching to the centre!!!!!!
              kglad Adobe Community Professional & MVP

              you're welcome.

               

              (but, you should be looping through both for-loops from the end to the beginning.)