use of com.almasb.fxgl.physics.box2d.dynamics.joints.RevoluteJointDef in project FXGL by AlmasB.
the class JointSample method initGame.
@Override
protected void initGame() {
getGameWorld().addEntity(Entities.makeScreenBounds(50));
PhysicsComponent physics = new PhysicsComponent();
Entity block = Entities.builder().at(200, 200).viewFromNodeWithBBox(new Rectangle(50, 50)).with(physics).buildAndAttach(getGameWorld());
PhysicsComponent physics2 = new PhysicsComponent();
physics2.setBodyType(BodyType.DYNAMIC);
FixtureDef fd = new FixtureDef();
fd.setDensity(1.0f);
physics2.setFixtureDef(fd);
Entity ball = Entities.builder().at(200, 300).bbox(new HitBox("main", BoundingShape.circle(15))).viewFromNode(getAssetLoader().loadTexture("ball.png", 30, 30)).with(physics2).buildAndAttach(getGameWorld());
Line line = new Line();
line.setStartX(block.getCenter().getX());
line.setStartY(block.getCenter().getY());
// line.startXProperty().bind(block.getPositionComponent().xProperty());
// line.startYProperty().bind(block.getPositionComponent().yProperty());
line.endXProperty().bind(ball.getPositionComponent().xProperty().add(15));
line.endYProperty().bind(ball.getPositionComponent().yProperty().add(15));
getGameScene().addGameView(new EntityView(line));
RevoluteJointDef rDef = new RevoluteJointDef();
rDef.bodyA = physics.getBody();
rDef.bodyB = physics2.getBody();
rDef.collideConnected = false;
rDef.localAnchorA = new Vec2(0, 0);
rDef.localAnchorB = new Vec2(0, 5);
rDef.enableLimit = true;
rDef.lowerAngle = (float) (FXGLMath.toRadians(-180.0f));
rDef.upperAngle = (float) (FXGLMath.toRadians(180.0f));
rDef.enableMotor = true;
rDef.motorSpeed = (float) (FXGLMath.toRadians(30));
rDef.maxMotorTorque = 15.0f;
joint = (RevoluteJoint) getPhysicsWorld().getJBox2DWorld().createJoint(rDef);
}
Aggregations