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:
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)
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!
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);
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);
{
@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!