Great, so I went to the source code of Box2DX, found the "ContactListener" class. It's an interface actually.
These comments lie above the interface's definition:
/// Implement this class to get contact information. You can use these results for
/// things like sounds and game logic.
You can also get contact results by
/// traversing the contact lists after the time step. However, you might miss
/// some contacts because continuous physics leads to sub-stepping.
/// Additionally you may receive multiple callbacks for the same contact in a
/// single time step.
/// You should strive to make your callbacks efficient because there may be
/// many callbacks per time step.
/// @warning You cannot create/destroy Box2DX entities inside these callbacks.
I thought: "Great, I can use that list to avoid using this". So I tried doing "world." for the auto completion to pop up. Nothing about GetContacts(), GetContactLists(), etc. Only GetContactCount() - useless for what I want to do. I checked the source code, there's a line in the World class:
// Do not access
internal Contact _contactList;
So I tried to inherit. There were 4 methods to implement:
Code:
void BeginContact(Contact contact);
void EndContact(Contact contact);
void PreSolve(Contact contact, Manifold oldManifold);
void PostSolve(Contact contact, ContactImpulse impulse);
So I wrote it like this:
Code:
/// Called when two fixtures begin to touch.
public void BeginContact(Contact contact)
{
Console.WriteLine("contact");
}
public void EndContact(Contact contact)
{
}
public void PreSolve(Contact contact, Manifold oldManifold)
{
}
public void PostSolve(Contact contact, ContactImpulse impulse)
{
}
Guess what? Compiler error!!!
Error 8 The type or namespace name 'ContactImpulse' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Minas\Documents\Visual Studio 2010\Quest of Antheia\Quest of Antheia\Quest of Antheia\src\MyContactListener.cs 33
I was not missing any using directive. I don't know about the assembly reference (what is it anyway?).
I deleted the PostSolve() method, and did world.setContactListener(new MyContactListener());
That should print "contact" every time there's a contact (I have the console terminal enabled).
Nothing is printed though...
What is wrong here?