简体   繁体   English

Box2d仅与一个身体碰撞

[英]Box2d collide only with one body

Sorry if there is another thread like this one, but i cannot find a solution.. 对不起,如果有另一个这样的线程,但我找不到解决方案。

I have a box2d game and i need to make one body to collide ONLY with the player and nothing else. 我有一个box2d游戏,我只需要使一个身体与玩家碰撞即可,别无其他。 Can you help me? 你能帮助我吗? How to define the mask bits, or the groups? 如何定义屏蔽位或组?

I found a solution (i write on LibGDX). 我找到了解决方案(我在LibGDX上写过)。 I use setContactFilter(). 我使用setContactFilter()。 I implemented this interface and override shoudCollide() 我实现了此接口并覆盖shoudCollide()

public class BackgroundContactFilter implements ContactFilter {
 @Override
 public boolean shouldCollide(Fixture fixtureA, Fixture fixtureB){
  return false;
 }

}

All interactions are disabled with this code. 此代码将禁用所有交互。

I hope that this would be helpful to someone. 我希望这会对某人有所帮助。

Heres a great article that will walk you through everything you need to know about masks and groups: 这是一篇很棒的文章,它将带您逐步了解面具和组所需的所有知识:

http://www.aurelienribon.com/blog/2011/07/box2d-tutorial-collision-filtering/ http://www.aurelienribon.com/blog/2011/07/box2d-tutorial-collision-filtering/

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

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