use of com.almasb.fxgl.entity.components.BoundingBoxComponent in project FXGL by AlmasB.
the class BoundingBoxComponentTest method testSerialization.
@Test
public void testSerialization() {
bbox.addHitBox(new HitBox("BOX", BoundingShape.box(30, 40)));
// write
Bundle bundle = new Bundle("BBOXTest");
bbox.write(bundle);
Entity e2 = new Entity();
// read
BoundingBoxComponent bbox2 = e2.getBoundingBoxComponent();
bbox2.read(bundle);
assertThat(bbox2.getWidth(), is(30.0));
assertThat(bbox2.getHeight(), is(40.0));
List<HitBox> boxes = bbox2.hitBoxesProperty();
assertThat(boxes.size(), is(1));
assertThat(boxes.get(0).getName(), is("BOX"));
assertThat(boxes.get(0).getWidth(), is(30.0));
assertThat(boxes.get(0).getHeight(), is(40.0));
}
use of com.almasb.fxgl.entity.components.BoundingBoxComponent in project FXGL by AlmasB.
the class PhysicsWorld method createFixtures.
private void createFixtures(Entity e) {
BoundingBoxComponent bbox = e.getBoundingBoxComponent();
PhysicsComponent physics = e.getComponent(PhysicsComponent.class);
FixtureDef fd = physics.fixtureDef;
for (HitBox box : bbox.hitBoxesProperty()) {
Shape b2Shape = createShape(box, e);
// we use definitions from user, but override shape
fd.setShape(b2Shape);
Fixture fixture = physics.body.createFixture(fd);
fixture.setHitBox(box);
}
}
Aggregations