Gio,
I have broken the stickman into 3 fixtures head, body and foot. The onCollision data returns which two fixtures are in collision. It is easiest to figure out which fixtures are in collision by referring to the name that was set via the fixture user data. Based on the box2d api, you should be able to set and get fixture user data. So, for example, when a collision occurs between the "head" of the stickman and a platform, I turn off collisions so he can pass through using this check:
else if ((data.contact.m_fixtureB.m_userData == "head" && data.contact.m_fixtureA.m_userData == "platform") || (data.contact.m_fixtureA.m_userData == "head" && data.contact.m_fixtureB.m_userData == "platform"))
When I do it the box2d way via fixture user data everthing works fine. When I try to do it the way you are suggesting
else if ((data.contact.m_fixtureB.isHead == true && data.contact.m_fixtureA.m_userData == "platform") ||
(data.contact.m_fixtureA.isHead == true && data.contact.m_fixtureB.m_userData == "platform"))
It does not work.I think the reason is because, the box2d engine does not keep/pass the extra information you set on a fixture. So even though it is accessible/visible in wade, it is ignored by the physics engine. The fixture user data was added for this specific case. As I pointed out above, it is a one line change to the code, and then you could just do something like this when creating a fixture
fixtures: {
0: { density: 1, friction: 0.5, restitution: 0.4, shapeType: "box",
spriteIndex: 0, isSensor: false, autoCalculateShape: true,
filter: { groupIndex: 0, categoryBits: 1, maskBits: 65535, userData: "head" }
},
Rather then having to do it manually like:
var fixtures = player.physics.getFixtureList();
fixtures.m_userData = "head";
Regarding the other point, I am referring to the getFixtureList() in the physics behavior api "Get a list of fixtures attached to this object Returns: {Array} An array of fixtures attached to this physics body"
var fix = player.physics.getFixtureList();
console.log(fix); --> returns b_d.b2Fixture {m_proxyCount: 1, m_filter: b…d.b2Filter, m_userData: "head", m_friction: 0.5, m_restitution: 0.4…}
console.log(fix[0]) --> undefined
console.log(fix[1]) --> undefined
So, when I set and reset the stickman as a sensor (to pass through platforms) or not (normal collision) I use
// set the three fixtures of the player to the value passed in
// set sensor to true to not have collisions, false to have collisions
this.setSensor = function(val) {
self.owner.isSensor = val;
var fixtures = self.owner.physics.getFixtureList();
while (fixtures != null) {
fixtures.m_isSensor = val;
fixtures = fixtures.m_next;
}
} // end setSensor
The api definition implies that you should be able to access the returned values via fixtures[0],fixtures[1], fixtures.length, etc. So, you should either change the definition in the api or (MY VOTE) populate the array before returning from getFixtureList().
cheers - shri