1 Reply Latest reply on Jun 5, 2011 9:57 AM by UltimateFlashxz

    Flash Game Ground HELP!

    Wasin_Mike

      Hello all, I just started with flash and I'm pretty new to the language.

       

      I am currently making a game in flash and have a sprite that needs to jump up to platforms.

      He stands on the first rectangle I made but doesn't land on the others and passes right through them.

       

      I have changed the character code many times to no avail. I have tried other ways but he falls through the main ground platform when I change.

       

      Here's the code on my character, there is no code on the platforms. (I have tried coding the platforms which don't help either)

       

       

      onClipEvent (load) {

      speed = 8;

      isJumping = false;

      jumpSpeed = 0;

      startY = _y;

      scale = _xscale;

      }

       

      onClipEvent (enterFrame) {

      if (isJumping) {

      _y += jumpSpeed;

      jumpSpeed += .86;

      if (_y>=startY) {

      _y = startY;

      isJumping = false;

      speed = 8;

      }

       

      } else {

      if (Key.isDown(Key.UP)) {

      isJumping = true;

      jumpSpeed = -15;

      speed = 8;

      }

      }

       

      if (Key.isDown(Key.LEFT)) {

      play();

      _x -= speed;

      _xscale = -scale;

      } else {

       

      if (Key.isDown(Key.RIGHT)) {

      play();

      _x += speed;

      _xscale = scale;

      } else {

      stop();

      }

      }

      }

       

       

      If there is more info I can provide to help, I will.

       

      Thank you.

        • 1. Re: Flash Game Ground HELP!
          UltimateFlashxz

          to have a game with Gravity, Jumping, and Ground Detection, first you need to make sure you enable all of these.

           

          GRAVITY-

          Gravity sounds weird and tricky but its also very simple.

          Theres a simple layout of code to enable Gravity.

           

          onClipEvent (load) {

               var Grav:Number = 0;

               var Gravity:Number = 5;

          }

          onClipEvent (enterFrame) {

               _y += Grav;

               Grav += Gravity;

               }

          }

           

          What that does is adds a consistent pull on the MC you place it into. Adding a Gravity like effect.

           

          JUMPING-

          Jumping is also very simple once you've done it once or twice, and as i seen in your code you have.

          I will add Jumping to the previous code now.

           

           

          onClipEvent (load) {

               var Grav:Number = 0;

               var Gravity:Number = 5;

               var maxJump:Number = -22

          }

          onClipEvent (enterFrame) {

               _y += Grav;

               Grav += Gravity;

               }

           

               if (Key.isDown(Key.UP)) {

               Grav = maxJump;

               }

          }

           

           

          The maxJump variable is the height of the jump and can be modified to your liking, REMEMBER to always have the number as a minus - since flashes y axis is backwards.

           

           

          GROUND DETECTION-

          This is something i did not see in your code, which i believe it your issue.

          Ground Detection is very simple but hard to figure out with out good know how of Flash.

           

          First, make your Ground convert it to a MC, name it whatever you like.

          Second, set the Instance Name of your Ground MC, to "Ground" (no brackets).

          Third make sure all of you level/games ground is within this MC or within another MC with "Ground" as the Instance Name.

           

          I will add the Ground Detection to the previous code now.

           

           

           

          onClipEvent (load) {

               var Grav:Number = 0;

               var Gravity:Number = 5;

               var maxJump:Number = -22

               var touchingGround:Boolean = false;

               var Ground:MovieClip = _root.ground;

          }

          onClipEvent (enterFrame) {

               _y += Grav;

               Grav += Gravity;

           

               while (Ground.hitTest(_x, _y, true)) {

                    _y -= Gravity;

                    Grav = 0;

               }

               if (Ground.hitTest(_x, _y+5, true)) {

                    touchingGround = true;

               } else {

                    touchingGround = false;

               }

           

               if (Key.isDown(Key.UP) && touchingGround){

                    Grav = maxJump;

               }

          }

           

           

          Take your time to learn this and study it and re-build it on your own, or just use it and add to it.

           

          Message was edited by: UltimateFlashxz