Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: Body

[23:7] extends: FxObj

Wraps jbox2d's Body (com.almasb.fxgl.physics.box2d.dynamics.Body), the runtime physics body created by World.createBody. Carries the type, position, angle, linear / angular velocity, damping flags, mass data, and the attached fixtures. The Aussom wrapper exposes the read-write surface most users need. Lower-level API (transform, world-vector helpers, mass data, etc.) is reachable directly on this.obj.

Methods

  • Body ()

    Empty default constructor; populated by adopt.

  • adopt (object Ajo)

    Wraps an existing Body AussomJavaObject.

  • getType ()

    Returns the body type enum AJO (STATIC / KINEMATIC / DYNAMIC).

  • setType (object TypeAjo)

    Sets the body type from a BodyType enum AJO.

  • getPosition ()

    Returns the world-coordinate position as a Vec2 wrapper.

  • getAngle ()

  • setTransform (object PositionVec, double Angle)

    Snaps the body to (position, angle).

    • @p PositionVec is a Vec2 wrapper.
    • @p Angle is the angle in radians.
  • getWorldCenter ()

    Returns the world center of mass as a Vec2 wrapper.

  • getLocalCenter ()

    Returns the local center of mass as a Vec2 wrapper.

  • getLinearVelocity ()

    Returns the linear velocity as a Vec2 wrapper.

  • setLinearVelocity (object VelocityVec)

  • getAngularVelocity ()

  • setAngularVelocity (double V)

  • getLinearDamping ()

  • setLinearDamping (double V)

  • getAngularDamping ()

  • setAngularDamping (double V)

  • getMass ()

  • getInertia ()

  • getGravityScale ()

  • setGravityScale (double V)

  • getTorque ()

  • setTorque (double V)

  • applyForce (object ForceVec, object PointVec)

    Applies a force at a world point.

  • applyForceToCenter (object ForceVec)

  • applyTorque (double V)

  • applyLinearImpulse (object ImpulseVec, object PointVec, bool Wake)

  • applyAngularImpulse (double V)

  • isBullet ()

  • setBullet (bool V)

  • isAwake ()

  • setAwake (bool V)

  • isActive ()

  • setActive (bool V)

  • isSleepingAllowed ()

  • setSleepingAllowed (bool V)

  • isFixedRotation ()

  • setFixedRotation (bool V)

  • getEntity ()

    Returns the attached Entity wrapper (or null).

  • setEntity (object EntityObj)

  • getUserData ()

  • setUserData (Data)

  • getWorld ()

    Returns the owning World AJO.

  • createFixture (object FixtureDefObj)

    Creates a fixture from a FixtureDef wrapper.

  • createFixtureShape (object ShapeAjo, double Density)

    Creates a fixture from a Shape + density.

  • destroyFixture (object FixtureAjo)

    Destroys a fixture from this body. The Fixture argument is the raw AJO returned by createFixture / createFixtureShape -- no Aussom wrapper type for Fixture exists in this layer.

  • getFixtures ()

    Returns the list of attached fixtures as a Java List AJO.

  • getTransform ()

    Returns the body's Transform (position + rotation) as a raw AJO. The Transform class is not wrapped — call .invokeRaw on the returned AJO for direct access.

  • getMassData (object MassDataAjo)

    Fills a MassData AJO with the body's mass / center / inertia. Pass a Java-allocated MassData AJO; the method writes into it.

    • @p MassDataAjo is the AJO to populate.
  • setMassData (object MassDataAjo)

    Replaces the body's mass data with the supplied MassData AJO. Used to override the mass / center / inertia computed from attached fixtures.

  • resetMassData ()

    Recomputes the body's mass data from its attached fixtures. Call after adding, removing, or changing fixtures.

  • getWorldPoint (object LocalVec)

    Converts a body-local point to world coordinates.

    • @p LocalVec is a Vec2 wrapper in body coordinates.
    • @r A new Vec2 wrapper in world coordinates.
  • getWorldVector (object LocalVec)

    Converts a body-local direction vector to world coordinates.

    • @p LocalVec is a Vec2 wrapper in body coordinates.
    • @r A new Vec2 wrapper in world coordinates.
  • getLocalPoint (object WorldVec)

    Converts a world-coordinate point to body-local coordinates.

    • @p WorldVec is a Vec2 wrapper in world coordinates.
    • @r A new Vec2 wrapper in body-local coordinates.
  • getLocalVector (object WorldVec)

    Converts a world-coordinate direction vector to body-local.

    • @p WorldVec is a Vec2 wrapper in world coordinates.
    • @r A new Vec2 wrapper in body-local coordinates.
  • getLinearVelocityFromWorldPoint (object WorldVec)

    Returns the velocity at a world-coordinate point as a Vec2. Useful when the body has angular velocity.

  • getLinearVelocityFromLocalPoint (object LocalVec)

    Returns the velocity at a body-local point as a Vec2.

  • getSleepTime ()

    Returns the float-second time this body has been asleep.

  • shouldCollide (object OtherBody)

    Returns true if the supplied Body would collide with this one under the current category / mask / group settings.

  • getJointList ()

    Returns the head of the joint linked list as a raw JointEdge AJO (or null when no joints are attached). The JointEdge class is not wrapped; iterate via .invokeRaw("getNext") on the AJO.

  • getContactList ()

    Returns the head of the contact linked list as a raw ContactEdge AJO (or null when no active contacts). The ContactEdge class is not wrapped; iterate via .invokeRaw("getNext") on the AJO.