简体   繁体   中英

Disable collision completely of a body in AndEngine Box2D

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.

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.

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM