I have a basic class for detecting collisions but I can't figure out how to see what bodies are colliding to trigger the appropriate event. Lets say I have a pong game and in it a ballBody and topwallBody. How would I figure out if these are colliding or not. Here is the class I'm using just to give you an idea.
class MyListener : public b2ContactListener
{
void BeginContact(b2Contact* contact)
{
b2Fixture* fixtureA = contact->GetFixtureA();
b2Fixture* fixtureB = contact->GetFixtureB();
b2Body* body1 = fixtureA->GetBody();
b2Body* body2 = fixtureB->GetBody();
cout << "started";
}
void EndContact(b2Contact* contact)
{
cout << "ended\n";
}
};
MyListener listener;
world.SetContactListener(&listener);
It looks like I can get the bodies in the pointers but I have no idea how to compare them to other bodies.
When new custom menu is added, its entry is added into several tables.
_term_taxonomy
with a column taxonomy
and value nav_menu
.term_id
is also in table:_terms
with the title of menu which is shown in admin panel_term_relationship
will contain term_texonomy_id
from 1) and connection to all object_id which will be linked to all _post
table having sub_menu
and below level menu._postmeta
will contain all the details related to menu and submenu for each object_id
from _posts
table.Navigation menu items are stored in the wp_posts table with post_type = 'nav_menu_item'
.
When you create the bodies, set the userdata to something meaningful, but be consistent :) A good tip is to always have the same kind and type of data in there, an entity id or reference to an actor.
Straight from the documentation:
b2BodyDef bodyDef;
bodyDef.userData = &myActor;
So if you went this road you would get the actor from the b2Body
and inform it of the collision, or do something else.
Also from the docs:
b2Fixture* fixtureA = myContact->GetFixtureA();
b2Body* bodyA = fixtureA->GetBody();
MyActor* actorA = (MyActor*)bodyA->GetUserData();
In the code above you would have the actor/entity and could do whatever you would like... actorA.explode()
.
Being consistent will likely save you from insanity. If one sticks all kinds of data in there it'll become really hard knowing what data is in what body. Plus you can't really handle the contacts in any generic way.
The answer Skurmedel gave helped me immensely on this. I thought I would add a little bit of information from what I was doing to solve this.
I, like the OP, wanted to check what was hitting what. I have hearts bouncing around inside the walls of the game screen and wanted to know if they are hitting other hearts, or the walls.
I used this code to view the contact
world.setContactListener(new ContactListener() {
@Override
public void beginContact(Contact contact) {
Gdx.app.log("GameScreen", "Contact Made! Fixture A: " + contact.getFixtureA().getBody().getUserData().toString());
Gdx.app.log("GameScreen", "Contact Made! Fixture B: " + contact.getFixtureB().getBody().getUserData().toString());
}
And within my heart object I overrode the toString method to simply return 'Hear' for now. I am setting the userData for the body as the whole sprite object, so I have flexibility with the body in the object itself.
Not having my actual class references for the floor, walls, and ceiling I simply set the userData as 'Floor' etc.
GameScreen: Contact Made! Fixture A: Ground
GameScreen: Contact Made! Fixture B: Heart
Using this method, and beefing it up later, I will be able to change how the objects react based on who they are contacting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With