Libgdx让灯光忽略身体

Oon*_*nej 4 java box2d libgdx

我有一个与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);
Run Code Online (Sandbox Code Playgroud)

小智 11

您可以使用以下方法:

cone.setContactFilter(categoryBits,groupIndex,maskBits);

其中,cone是ConeLight类型的对象.现在这个灯会忽略具有指定categoryBits,groupIndex和maskBits的物体.

您可以通过以下方式通过主体夹具设置categoryBits,groupIndex和maskBits-

fixture.filter.categoryBits =你的价值;

(categoryBits:碰撞类别位.通常你只需设置一位.)

fixture.filter.groupIndex =你的价值;

(对groupIndex:碰撞组允许一组特定对象来从未碰撞(负)或总是碰撞(正)零意味着没有碰撞组非零群滤波总是获胜对的屏蔽位.)

fixture.filter.maskBits =你的价值

(maskBits:碰撞掩码位.这表示此形状可以接受碰撞的类别.)

如果你希望某些实体忽略所有灯光,那么你可以使用以下 Light .setContactFilter(categoryBits,groupIndex,maskBits)