简体   繁体   English

完全禁用AndEngine Box2D中的物体碰撞

[英]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. 我不想让一个物体与其他物体发生碰撞,有人告诉我将isSensor标志设置为true,但是我还是无法获取并设置该标志。 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. 将传感器设置为true不会对身体造成碰撞影响。 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. 但是由于物理原因不会发生碰撞效果,因此您需要检查身体是否将isSesors设置为true,才能在接触侦听器中执行任何操作。

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. 如果您不希望它们发生冲突,请给灯具的filterindex赋予负值,而如果他们希望发生冲突,则给正值。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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