I'm trying to swap the fixtures associated with a body after colliding with a specific obstacle.
I can listen to the collision event by extending b2ContactListener
. I tested it with a trace and it's working. My listener function in the main game class calls a Player
method that makes the swap. But it's just not working.
The body is stored in public var _body:b2Body;
in the Player
class.
The method I'm calling goes like this:
public function changeFixture():void {
var newShape:b2CircleShape = new b2CircleShape(1);
var myFixtureDef:b2FixtureDef = new b2FixtureDef();
// Here I set density, friction, restitution, etc... Not important now...
myFixtureDef.shape = newShape;
_body.DestroyFixture(_oldFixture);
_body.CreateFixture(myFixtureDef);
// I know the method is called because this works
trace('Yay! I'm working!');
}
What might be wrong?