Disable collision completely of a body in AndEngin

2019-05-30 17:29发布

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.

3条回答
贪生不怕死
2楼-- · 2019-05-30 17:41

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.

查看更多
看我几分像从前
3楼-- · 2019-05-30 17:43

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);
查看更多
可以哭但决不认输i
4楼-- · 2019-05-30 17:47

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

查看更多
登录 后发表回答