ContactListener - Contact Side [Android Game]

Hello, I'm developing an Android game using AndEngine (Android game's and app's engine) using Box2D extension.

I have 2D TILED map, generated from XML. I'm creating Box body using physic for every Tile, to prevent player falling down while being on tile, with this way:

Code:
                    final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.1f, 0.5f);
         PhysicsFactory.createBoxBody(this.mPhysicsWorld, s, BodyType.StaticBody, wallFixtureDef);


I have also jump method, to allow player simply JUMP, to disable possibility player to jump again and again, without touching tile, I'm using boolean jump = false, which is enabled while player is jumping and disabled while there is contact with tile (means player may jump, because he is touching "ground" - tile)

Now the problem is, it doesn't matter which side "of the player" is touching Tile (in this case player should touch tile with LEGS [down - bottom side of the body)

Code:
       ContactListener contactListener = new ContactListener()
       {
          @Override
          public void beginContact(Contact contact)
          {
             jumping = false;
           }
              
           @Override
           public void endContact(Contact contact) { }

         @Override
         public void preSolve(Contact contact, Manifold oldManifold) { }
         
         @Override
         public void postSolve(Contact contact, ContactImpulse impulse) { }
       };
      
      mPhysicsWorld.setContactListener(contactListener);


Simply my target is to enable jumping only while body (player) is touching ground (tile) with down side of the body (for example legs of the player)

I will be thankful for help or hints about how to achieve my goal.

This library is remarkable, thanks everyone!
Your beginContact is way too simple. This will be called for all fixtures that come into contact regardless of whether they are your player or not. Unless you have only one dynamic body moving around, and it can only touch at most one other fixture at a time (not likely in a tiled world) then you will need to check that the thing that beginContact'ed is actually your player. I would use an integer to keep track of the current number of contacts instead of a bool.

It's not in Java, but this might help with these methods:
http://www.iforce2d.net/b2dtut/jumpability
other options to consider:
  • Making a sensor at the bottom of your object to detect if he's standing on top of something
  • Checking the 'normal' of the contact to determine the slope (jump in that direction, or maybe can't jump if the slope is too great)

Original thread: https://box2d.org/forum/viewtopic.php?t=7697