Libgdx make lights ignore body

I have a libgdx game working with Box2d and Box2d Lights.

My questions are: how can I get Bodys / Bodydefs to ignore the light source from Box2d Light and not cast shadows?

Thanks.

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); 
+4
source share
2 answers

You can use the following method:

cone.setContactFilter ( categoryBits , groupIndex , maskBits );

where the cone is an object of type ConeLight . Now this light will ignore bodies having the specified categories Bits, groupIndex and maskBits.

You can set the Bits, groupIndex and maskBits categories through the body mount in the following way -

fixture.filter.categoryBits = your value;

(categoryBits: collision category bit. Usually you just set one bit.)

fixture.filter.groupIndex = your value;

(groupIndex: collision groups allow a particular group of objects to never collide (negatively) or always collide (positively). no collision group. Nonzero group filtering always wins against the mask bit.)

fixture.filter.maskBits = your value

(maskBits: bit of the collision mask. It indicates the categories this form will take for the collision.)

If you want some bodies to ignore ALL LIGHTS.then, you can use the following Light .setContactFilter (categoryBits, groupIndex, maskBits)

+10
source

I believe contact filters can only be applied to ALL LIGHTS using Box2D Lights. I tried to set them using the setContactFilter method referenced by aug13, but this is a static method that inherits from Light and cannot be called from an object. I do not know if this could at some point in the past.

From the docs:

 public static void setContactFilter(short categoryBits, short groupIndex, short maskBits) 

create a new contact filter for ALL LIGHTINGS with parameters

0
source

Source: https://habr.com/ru/post/1499938/


All Articles