Simplifying building bodies and joints with libGDX Box2D - 2

BodyBuilder, which I commented on a previous post, has been updated to work with multiple fixtures, keeping simplicity.

Internally, it uses a FixtureDef builder named FixtureDefBuilder which lets you specify a fixture definition for each fixture.

Here is an example of how it looks now it supports multiple fixture definitions:

Body body = bodyBuilder 
				.circleShape(radius * 0.1f) 
		.position(x, y) 

The previous example shows how to declare two fixtures for a Body, one of them is a sensor. For you to know, I am using that code in Super Flying Thing to declare the destination planet (that's the name for now), the sensor is to detect when the ship is near to trigger an event and then attach it to the planet by creating a Box2D Joint.

If you are a game programmer, it could be useful to maintain your code clean and simple.

VN:F [1.9.22_1171]
Rating: 4.2/5 (6 votes cast)
Simplifying building bodies and joints with libGDX Box2D - 2, 4.2 out of 5 based on 6 ratings
  • drorasta

    Hi there, nice classes, you should dispose all shapes in your FixtureDefBuilder class after finishing using them (-;

  • Ariel Coppes

    Well, the idea is to use it with BodyBuilder which disposes all the fixtureDef shapes on method reset() (which is called internally on build).

  • drorasta

    ah ok, just missed it (-; thanks

  • behr

    Hey I'm trying to use your classes, just what I was looking for!
    I having a problem with fixed rotation. I'm trying to apply a force off center of a rectangle as to rotate it, but bodies created with your classes won't rotate. I have inspected the .fixedRotation() method, and see that it is correctly not appending that tag, but for some reason the rotation is still locked.
    Specifically, it seems like "body".getWorldPoint is returning incorrect/strange values when called on bodies generated with your classes. Its probably something I'm doing wrong as I'm new to box2d. Thanks for the great classes though!