Fixture(Body body, FixtureDef def) { this.body = body; shape = def.getShape().clone(); userData = def.getUserData(); density = def.getDensity(); friction = def.getFriction(); restitution = def.getRestitution(); isSensor = def.isSensor(); filter.set(def.getFilter()); // Reserve proxy space int childCount = shape.getChildCount(); proxies = new FixtureProxy[childCount]; for (int i = 0; i < childCount; i++) { proxies[i] = new FixtureProxy(); } }
/** * Creates a fixture from a shape and attach it to this body. * This is a convenience function. * Use FixtureDef if you need to set parameters like friction, restitution, user data, or filtering. * If the density is non-zero, this function automatically updates the mass of the body. * Note: this function is locked during callbacks. * * * @param shape the shape to be cloned. * @param density the shape density (set to zero for static bodies). */ public Fixture createFixture(Shape shape, float density) { fixDef.setShape(shape); fixDef.setDensity(density); return createFixture(fixDef); }
private void createSensors(Entity e) { PhysicsComponent physics = e.getComponent(PhysicsComponent.class); if (physics.getSensorHandlers().isEmpty()) return; forEach(physics.getSensorHandlers().keys(), box -> { Shape polygonShape = createShape(box, e); FixtureDef fd = new FixtureDef() .sensor(true) .shape(polygonShape); Fixture f = physics.body.createFixture(fd); f.setUserData(box); }); }
private void createSensors(Entity e) { PhysicsComponent physics = e.getComponent(PhysicsComponent.class); if (physics.getSensorHandlers().isEmpty()) return; forEach(physics.getSensorHandlers().keys(), box -> { box.bindXY(e.getTransformComponent()); Shape polygonShape = createShape(box, e); FixtureDef fd = new FixtureDef() .sensor(true) .shape(polygonShape); Fixture f = physics.body.createFixture(fd); f.setHitBox(box); }); }
Fixture(Body body, FixtureDef def) { this.body = body; shape = def.getShape().clone(); userData = def.getUserData(); density = def.getDensity(); friction = def.getFriction(); restitution = def.getRestitution(); isSensor = def.isSensor(); filter.set(def.getFilter()); // Reserve proxy space int childCount = shape.getChildCount(); proxies = new FixtureProxy[childCount]; for (int i = 0; i < childCount; i++) { proxies[i] = new FixtureProxy(); } }
/** * Creates a fixture from a shape and attach it to this body. * This is a convenience function. * Use FixtureDef if you need to set parameters like friction, restitution, user data, or filtering. * If the density is non-zero, this function automatically updates the mass of the body. * Note: this function is locked during callbacks. * * * @param shape the shape to be cloned. * @param density the shape density (set to zero for static bodies). */ public Fixture createFixture(Shape shape, float density) { fixDef.setShape(shape); fixDef.setDensity(density); return createFixture(fixDef); }