I am working on a Bubble Shooter type game where I want a body not to collide with any thing else when its burst or falling down. I cant use collision filtering because all the bodies on the scene are of same type. I want to disable the collision. I don't want to collide a body with any other body.Some one told me to set the isSensor flag to true but again I am not able to get the flag and set it. Please help.
问题:
回答1:
Found the answer:
for(int i=0; i<getBody().getFixtureList().size();i++){
this.getBody().getFixtureList().get(i).setSensor(true);
}
Setting the sensor to true will cause no collisions effects for a body. But remember actually collisions are occurring and contact listeners are called. But collision effect due to physics is not happening so you need to check that if the body has isSesors set to true do nothing in contact listeners.
回答2:
You can also use mask bit and category bit property to change behaviour of some body and other body act as normal one.
This way you can create multiple groups of bodies which response to collision as group. Means one group has different collision behaviour than other one.
Using this method you can perform collision filtering. That thing represented in the following example.
Physics Collision Filtering
回答3:
Give negative value to filterindex of your fixture if you don't want them to collide and positive value if you want them to collide.
For removing collision
public static final FixtureDef PLAYERS_FIXTURE_DEF = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f, false, CATEGORYBIT_PLAYERS, MASKBITS_WALL, (short)-1);
and for collision
public static final FixtureDef PLAYERS_FIXTURE_DEF = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f, false, CATEGORYBIT_PLAYERS, MASKBITS_WALL, (short)1);