use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class RevoluteJointSample method initGame.
@Override
protected void initGame() {
getGameScene().setBackgroundColor(Color.LIGHTGRAY);
entityBuilder().buildScreenBoundsAndAttach(50);
// platform
entityBuilder().at(400, 400).viewWithBBox(new Rectangle(500, 20, Color.BROWN)).with(new PhysicsComponent()).buildAndAttach();
PhysicsComponent physics = new PhysicsComponent();
physics.setFixtureDef(new FixtureDef().density(1.1f));
physics.setBodyType(BodyType.DYNAMIC);
Entity block = entityBuilder().at(600, 100).viewWithBBox(new Rectangle(80, 50)).with(physics).buildAndAttach();
PhysicsComponent physics2 = new PhysicsComponent();
physics2.setBodyType(BodyType.DYNAMIC);
FixtureDef fd = new FixtureDef();
fd.setDensity(1.0f);
physics2.setFixtureDef(fd);
Entity ball1 = entityBuilder().at(600, 360).bbox(new HitBox("main", BoundingShape.circle(15))).view(texture("ball.png", 30, 30)).with(physics2).buildAndAttach();
PhysicsComponent physics3 = new PhysicsComponent();
physics3.setBodyType(BodyType.DYNAMIC);
physics3.setFixtureDef(fd);
Entity ball2 = entityBuilder().at(700, 360).bbox(new HitBox("main", BoundingShape.circle(15))).view(texture("ball.png", 30, 30)).with(physics3).buildAndAttach();
physics2.getBody().setAngularDamping(1f);
physics3.getBody().setAngularDamping(1f);
getPhysicsWorld().addRevoluteJoint(block, ball1, new Point2D(80, 50), new Point2D(15, 15));
getPhysicsWorld().addRevoluteJoint(block, ball2, new Point2D(0, 50), new Point2D(15, 15));
}
use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class RevoluteJointSample method createPhysicsEntity.
private Entity createPhysicsEntity() {
PhysicsComponent physics = new PhysicsComponent();
physics.setBodyType(BodyType.DYNAMIC);
physics.setFixtureDef(new FixtureDef().density(0.1f).restitution(0.3f));
return entityBuilder().at(getInput().getMousePositionWorld()).with(physics).build();
}
Aggregations