Thanks!
I think I got it working.
So, as the world is being initialized, it gets a
ContactListener.
Code:
PlayerContactListener p = new PlayerContactListener();
jboxWorld.setContactListener(p);
and the
ContactListener looks like this:
Code:
public class PlayerContactListener implements ContactListener {
@Override
public void beginContact(Contact contact) {
WorldManifold worldManifold = new WorldManifold();
contact.getWorldManifold(worldManifold);
//print the contact point and the normal
System.out.println(worldManifold.points[0].x + "," + worldManifold.points[0].y);
System.out.println(worldManifold.normal.x + "," + worldManifold.normal.y);
}
...
...
I noticed that I don't have to enable the
ContactListener anywhere. I only had to set the listener for the world and it started to check for contacts in the game.
-
Now I need to limit the loop so that only certain bodies are being checked. I need to know this information
(points and normals) only from one physics object, the "player" object.
Also, I saw that the normal is only one
Vector2. So it holds only 1
x and 1
y value. The problem is that the listener doesn't tell from which object those values are measured, the
A object or the
B object.
Also, I need to do massive checks for the player object
(as I need to apply forces and limit its movement as the object is against a wall), so is it wise to do those checks inside the
ContactListener? Can it even be done anywhere else?
If you have any tips on those issues please reply here. I will update my progress here and paste some code, so that this thread will be more helpful for other people in the future.