我在Box2d和Box2d Lights的作品中有一个libgdx游戏。

我的问题是如何让Bodys/Bodydefs忽略Box2d Light的光源而不转换阴影?

谢谢。

  PolygonShape groundBox = new PolygonShape();
  groundBox.setAsBox(2f, 2f);

  FixtureDef gridBox = new FixtureDef();
  gridBox.shape = groundBox;
  gridBox.density = 1.0f;

  gridBox.filter.groupIndex = GRID_GROUP;
  gridBox.filter.categoryBits = GRID_CAT;
  gridBox.filter.maskBits = GRID_MASK;

  bodyDefs[i][j] = new BodyDef();
  bodyDefs[i][j].position.set(j*factor + factor, i*factor + factor);
  bodyDefs[i][j].fixedRotation = true;
  bodyDefs[i][j].type = BodyDef.BodyType.DynamicBody;

  bodies[i][j] = world.createBody(bodyDefs[i][j]);
  bodies[i][j].createFixture(gridBox);

  handler = new RayHandler(world);
  handler.setCombinedMatrix(camera.combined);
  Filter filter = new Filter();
  filter.groupIndex = GRID_GROUP; // GRID_GROUP = 1
  filter.categoryBits = GRID_CAT; // GRID_CAT = 0x0001;
  filter.maskBits = GRID_MASK;    // GRID_MASK = 1;

  new PointLight(handler, 1000, Color.RED, 2000, 0, height);

  PointLight.setContactFilter(filter);

最佳答案

您可以使用以下方法:

cone.setContactFilter( categoryBits groupIndex maskBits );

其中圆锥体是类型的对象ConeLight 。现在,这种光将忽略具有
指定categoryBits,groupIndex和maskBits。

您可以通过主体中的固定装置来设置categoryBits,groupIndex和maskBits
按照以下方式

Fixture.filter.categoryBits =您的值(value);

(categoryBits:碰撞类别位。通常,您只需设置一个位。)

Fixture.filter.groupIndex =您的值(value);

(groupIndex:碰撞组允许某个对象组从不碰撞(负向)或始终碰撞(正向)。零表示
没有碰撞组。非零组过滤始终会赢得掩码位。)

Fixture.filter.maskBits =您的值(value)

(maskBits:碰撞 mask 位。这表明此形状将接受碰撞的类别。)

如果您希望某些物体忽略所有灯光,则可以使用以下内容
.setContactFilter(categoryBits,groupIndex,maskBits)

09-10 23:24