jetlag2d
    Preparing search index...

    Class PolygonBody

    A rigid body whose underlying shape is a convex polygon

    Hierarchy

    • RigidBodyBase
      • PolygonBody
    Index
    • Construct a PolygonBody

      Parameters

      • polygonCfg: { cx: number; cy: number; vertices: { x: number; y: number }[] }

        The basic shape configuration for the polygon

        • cx: number

          X coordinate of the center of the polygon

        • cy: number

          Y coordinate of the center of the polygon

        • vertices: { x: number; y: number }[]

          Vertices of the polygon, as points that are offsets relative to (cx, cy)

      • physicsCfg: PhysicsCfg = {}

        Optional physics configuration; see PhysicsCfg for the full set of options

      Returns PolygonBody

      A rigid body with a Polygon shape

    body: b2Body

    The physics body

    h: number

    Height of the body

    mainFixture: b2Fixture

    The entity's primary fixture

    passThroughId?: number[]

    Entities with a matching Id don't collide with each other

    radius: number

    Radius of a circumscribed circle, for culling

    scene: Scene

    The physics world where this body exists

    singleRigidSide?: DIRECTION

    Are collisions only valid from one direction? Expressed as a zone (see relativeZone in Behavior.ts): DIRECTION.N means "solid only when approached from above."

    stickySides: DIRECTION[] = []

    Which sides of the body are sticky, if any? DIRECTION.N means "stuff touching my top sticks."

    stickySpeedLimit: number = 0.5

    The fastest speed, relative to this body, at which something can stick to it. Configured via PhysicsCfg.stickySpeedLimit.

    w: number

    Width of the body

    • get bodyType(): "static" | "dynamic" | "kinematic"

      The type of this body: "static" (never moves), "kinematic" (moves only as it is told to), or "dynamic" (moves and responds to forces and collisions). Assign to it to change the type while the game is running.

      Returns "static" | "dynamic" | "kinematic"

    • set bodyType(type: "static" | "dynamic" | "kinematic"): void

      Change the type of this body

      Parameters

      • type: "static" | "dynamic" | "kinematic"

      Returns void

    • get collisionsEnabled(): boolean

      Report if this entity's main shape causes transfer of momentum when it collides with other entities (true) or not (false). This only concerns the main fixture -- the proximity fixture (see proximityRadius), if any, is always a sensor, regardless of this setting.

      Returns boolean

    • set collisionsEnabled(val: boolean): void

      Indicate whether this entity engages in physics collisions or not

      Parameters

      • val: boolean

        True or false, depending on whether the entity will participate in physics collisions or not

      Returns void

    • get proximityRadius(): number | undefined

      The radius (in meters) of this entity's proximity-sensor zone, or undefined if it has none.

      Returns number | undefined

    • set proximityRadius(radius: number | undefined): void

      Give this entity a proximity-sensor zone: a second, sensor-only fixture on the same body, separate from its normal solid fixture, so it can have both real physical collisions (or none, if collisionsEnabled is false) and a much larger "something is nearby" detection radius at the same time. Box2D fires contact events for this fixture exactly like any other, but Services/Collisions.ts routes them to ProximityBehavior instead of the normal collision dispatch. Pass undefined to remove an existing proximity zone.

      NB: Unlike the entity's main shape, the proximity radius does not automatically rescale when resize() is called.

      Parameters

      • radius: number | undefined

        The radius of the proximity zone, in meters, or undefined to remove it

      Returns void

    • get rotation(): number

      The current rotation of the entity, in radians

      Returns number

    • set rotation(rotation: number): void

      The current rotation of the entity, in radians

      Parameters

      • rotation: number

      Returns void

    • Add a revolute joint between this entity and some other entity, so that this entity can turn around a point on the other one. An entity can have as many joints as you like. Note that both entities need to have some mass (density can't be 0) or else this won't work.

      The joint that comes back can be changed later, such as with joint.SetMotorSpeed(speed), joint.SetMaxMotorTorque(torque), and joint.EnableMotor(true).

      Parameters

      • cfg: {
            anchor: Actor;
            anchorPoint: { x: number; y: number };
            limits?: { lower: number; upper: number };
            localPoint: { x: number; y: number };
            motor?: { speed: number; torque: number };
        }
        • anchor: Actor

          The entity around which this entity will rotate

        • anchorPoint: { x: number; y: number }

          The point (relative to center) where the joint fuses to the anchor

        • Optionallimits?: { lower: number; upper: number }

          Optional bounds on the rotation, in radians

        • localPoint: { x: number; y: number }

          The point (relative to center) where the joint fuses to this entity

        • Optionalmotor?: { speed: number; torque: number }

          Optional motor to make the joint turn: speed is in radians per second, and when in doubt, give a torque that is huge, like positive infinity

      Returns b2RevoluteJoint

      The joint that was created

    • Add velocity to this actor

      Parameters

      • x: number

        Velocity in X dimension

      • y: number

        Velocity in Y dimension

      Returns void

    • Create a weld joint between this entity and some other entity, to force the entities to stick together.

      Parameters

      • cfg: {
            angle: number;
            localPoint: { x: number; y: number };
            other: Actor;
            otherPoint: { x: number; y: number };
        }
        • angle: number

          The angle between the entities

        • localPoint: { x: number; y: number }

          The point (relative to center) where the joint fuses to this entity

        • other: Actor

          The entity that will be fused to this entity

        • otherPoint: { x: number; y: number }

          The point (relative to center) where the joint fuses to the other entity

      Returns b2WeldJoint

      The joint that was created

    • Apply a force to the actor

      Parameters

      • x: number

        The force to apply in the x dimension

      • y: number

        The force to apply in the y dimension

      Returns void

    • Give this entity a punch hitbox: a third, sensor-only fixture on the same body, offset from its center, so a melee attack can be modeled as a circle that moves rigidly with this entity -- no separate actor, no joint. Box2D fires contact events for this fixture exactly like any other; Services/Collisions.ts routes them to PunchBehavior instead of the normal collision dispatch. Replaces any punch hitbox already in progress; see disablePunch to remove it without replacing it.

      Parameters

      • cfg: { offsetX: number; offsetY: number; radius: number }
        • offsetX: number

          The x distance from this entity's center to the hitbox's center

        • offsetY: number

          The y distance from this entity's center to the hitbox's center

        • radius: number

          The radius of the hitbox

      Returns void

    • Copy an old fixture's density/elasticity/friction/sensor state onto mainFixture (the fixture that just replaced it), then destroy the old one. Shared by every subclass's resize(), since this tail is identical regardless of shape.

      Parameters

      • oldFix: b2Fixture

        The fixture that mainFixture is replacing

      Returns void

    • Return the center of the entity

      Returns Readonly<
          {
              x: number;
              y: number;
              Clone(): b2Vec2;
              Cross(v: Readonly<XY>): number;
              Dot(v: Readonly<XY>): number;
              GetAbs<T extends XY>(out: T): T;
              IsValid(): boolean;
              Length(): number;
              LengthSquared(): number;
          },
      >

    • Change the rotation of the body

      Parameters

      • delta: number

        How much to add to the current rotation

      Returns void

    • Resize a PolygonBody

      Parameters

      • scale: number

        The amount to scale the size by. 1 means "no change", >1 means "grow", fraction means "shrink".

      Returns void

    • Set a dampening factor to cause a spinning body to decrease its rate of spin

      Parameters

      • amount: number

        The amount of damping to apply

      Returns void

    • Change the position of an entity

      Parameters

      • cx: number

        The new X position, in meters

      • cy: number

        The new Y position, in meters

      Returns void

    • Set a dampening factor to cause a moving body to slow down without colliding with anything

      Parameters

      • amount: number

        The amount of damping to apply

      Returns void

    • Indicate that this actor should be immune to the force of gravity

      Returns void

    • Adjust the default physics settings (density, elasticity, friction) for this entity

      Parameters

      • cfg: { density?: number; elasticity?: number; friction?: number }
        • Optionaldensity?: number

          New density of the entity

        • Optionalelasticity?: number

          New elasticity of the entity

        • Optionalfriction?: number

          New friction of the entity

      Returns void

    • Indicate whether this body is allowed to rotate or not

      Parameters

      • val: boolean

      Returns void

    • Update the velocity

      Parameters

      • x: number

        The new x velocity

      • y: number

        The new y velocity

      Returns void