11 Replies Latest reply on Nov 22, 2010 7:04 AM by kglad

    Platform Game Help!

    miaklang

      Hi, I wonder if anyone could help me,
      I am trying to figure out how to do a simple platform game, and have got  the basics by checking out tutorials around the web, Im stuck on one  thing though, the health of my character, at the moment I have a hp mc  that takes you from frame to frame to less health, when the enemy hits  the character this code applies:

      onClipEvent(enterFrame) {
      if(_root.character.hitTest(this)) {
      _root.background.hp.nextFrame();
      }
      }

      This code make the enemy to constantly make the hp mc to go to next  frame, so my character will die if he touches the enemy for one or two  seconds..... What I would like instead is for the enemy to make hp move to next  frame and then the character will be untouchable for a few seconds  afterwards so he gets the chance to move away.

      Thank you to anybody that's got a suggestion to my problem.

       


       

      Edit/Delete  Message
        • 1. Re: Platform Game Help!
          kglad Adobe Community Professional & MVP

          you should not attach code to objects (like enemies).  remove that code and use:

           

          enemy_mc.onEnterFrame=function(){

          if(this.hitable && this.hitTest(_root.character)){

          _root.background.hp.nextFrame();

          this.hitable=false;

          setTimeout(resetF,3000,this);

          }

          }

           

          function resetF(enemy:MovieClip){

          enemy.hitable=true;

          }

           


           


           

          • 2. Re: Platform Game Help!
            miaklang Level 1

            Sorry, I'm just very new to flash...

             

            So if I dont attach any code to my "enemy" where should I attach the code? Do I need any onclipEvent before the code or is that all the code I need?

             

            Thank you for your help

            • 3. Re: Platform Game Help!
              kglad Adobe Community Professional & MVP

              you click on a frame (preferrably in a layer devoted to actionscript) and paste that code in the actions panel.  you also need to assign an instance name to that enemy.  you do that by clicking the enemy (to select it) and then in the properites panel, type enemy_mc.  while you have that enemy selected, remove all the code attached to it.

              • 4. Re: Platform Game Help!
                miaklang Level 1

                Thank you yet again, I have done it all exactly like explained, I clicked on the enemy mc on scene1 and named it enemy_mc in the instance name box in the properties panel, I've deleted all the code from the enemy that used to be there and I have created a new layer called actionsscript2 on scene1 and inserted the code, but when I test the game the character doesnt get hurt at all when he gets in contact with enemy. Don't know what I'm doing wrong.

                • 5. Re: Platform Game Help!
                  kglad Adobe Community Professional & MVP

                  try:

                   

                   

                  enemy_mc.onEnterFrame=function(){

                  if(!this.nothitable && this.hitTest(_root.character)){

                  _root.background.hp.nextFrame();

                  this.nothitable=false;

                  setTimeout(resetF,3000,this);

                  }

                  }

                   

                  function resetF(enemy:MovieClip){

                  enemy.nothitable=true;

                  }

                  • 6. Re: Platform Game Help!
                    miaklang Level 1

                    The character now gets injured, but just like before, the timer doesnt seem t

                    o work.

                     

                    I was just thinking.. since Ive built the whole game using codes on objects, could this have anything to do with it not working. For example the character has all the code in itself.

                     

                    Also what does the enemy in the code stand for, I mean the last two, I understand enemy_mc, but the enemy??

                     

                    Thanks

                    • 7. Re: Platform Game Help!
                      kglad Adobe Community Professional & MVP

                      again, you should not attach code to objects (like enemies).  remove that code and use:

                       

                      (ths above code)

                      • 8. Re: Platform Game Help!
                        miaklang Level 1

                        Sorry I think you misunderstood me, there is no code in my enemies, I'm only trying to figure out why it still doesnt work by letting you know that I've still got objects on stage with codes in them, for example the character, not the enemy.

                        This might be the reason why the code is not working?

                         

                        So here is where I'm at:

                        Enemy doesnt have any code

                        A layer on scene1 has been devoted only for as, and I've added the code:

                        enemy_mc.onEnterFrame=function(){

                         

                        if(!this.nothitable && this.hitTest(_root.character)){

                         

                        _root.background.hp.nextFrame();

                         

                        this.nothitable=false;

                         

                        setTimeout(resetF,3000,this);

                         

                        }

                         

                        }

                         

                         

                         

                        function resetF(enemy:MovieClip){

                         

                        enemy.nothitable=true;

                         

                        }

                         

                        and what happens is: character gets injured by enemy but the timing when the character is suppose to be untouchable doesnt work.

                         

                         

                         

                         

                        Thanks again for all your help.

                        • 9. Re: Platform Game Help!
                          kglad Adobe Community Professional & MVP

                          that's my error.  use:

                           

                          enemy_mc.onEnterFrame=function(){

                          if(!this.nothitable && this.hitTest(_root.character)){

                          _root.background.hp.nextFrame();

                          this.nothitable=true;

                          setTimeout(resetF,3000,this);

                          }

                          }

                           

                          function resetF(enemy:MovieClip){

                          enemy.nothitable=false;

                          }

                          • 10. Re: Platform Game Help!
                            miaklang Level 1

                            Great!!!

                             

                            It works!!

                             

                            Thank you so much

                            • 11. Re: Platform Game Help!
                              kglad Adobe Community Professional & MVP

                              you're welcome.