I am trying to understand how does it work.
In my game I use box2d physics, to handle contacts I use contact listener, example:
ContactListener contactListener = new ContactListener()
{
@Override
public void beginContact(Contact contact)
{
final Fixture x1 = contact.getFixtureA();
final Fixture x2 = contact.getFixtureB();
if (x1.getBody().getUserData() != null && x2.getBody().getUserData() != null)
{
if (x1.getBody().getUserData().equals("player"))
{
player.increaseFootContacts();
}
}
}
And here`s question, is there any order in those fixtures? (x1 or x2) after 2 test, I found out that in this case, my player will be x1, and other objects x2, should I also check reverse order ? (if x2 is player and so on) ?
No, there is no guarantee which fixture is which. You have to check for both possibilities, like this:
if ( (userdataA.equals("player") && userDataB.equals("ground")) ||
(userdataA.equals("ground") && userDataB.equals("player")) )
player.increaseFootContacts();
来源:https://stackoverflow.com/questions/14104813/box2d-contact-listener-fixtures-order