nape-js API
    Preparing search index...

    Class Shape

    Base class for physics shapes (Circle, Polygon). Never instantiated directly — use new Circle(...) or Polygon.box(...) etc.

    Hierarchy (View Summary)

    Index

    Accessors

    • get castBody(): any

      Cast to Body — returns the Body wrapper if this is a Body, else null.

      Returns any

    • get castCompound(): any

      Cast to Compound — returns the Compound wrapper if this is a Compound, else null.

      Returns any

    • get castShape(): any

      Cast to Shape — returns the Shape wrapper if this is a Shape, else null.

      Returns any

    • get fluidEnabled(): boolean

      If true, this shape participates in fluid interaction.

      Returns boolean

    • set fluidEnabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get id(): number

      Unique numeric identifier for this interactor.

      Returns number

    • get inertia(): number

      Contribution to moment of inertia (about local centroid, unit density).

      Returns number

    • get sensorEnabled(): boolean

      If true, this shape acts as a sensor (no physical response, only callbacks).

      Returns boolean

    • set sensorEnabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get userData(): Record<string, unknown>

      User-defined data storage object.

      Returns Record<string, unknown>

    Methods

    • Return true if the given world-space point lies inside this shape. Requires the shape to be attached to a Body.

      Parameters

      • point: Vec2

        The world-space point to test.

      Returns boolean

      True if the point is inside this shape.

    • Create a deep copy of this shape with the same type, geometry, material, and filter.

      Returns Shape

      A new Shape instance independent of this one.

    • Returns true if this is a Circle shape.

      Returns boolean

    • Rotate the shape's local vertices by angle radians.

      Parameters

      • angle: number

        Rotation in radians.

      Returns Shape

      this for chaining.

    • Scale the shape's local geometry. Circles require uniform scaling.

      Parameters

      • scaleX: number

        Horizontal scale factor (must be non-zero).

      • scaleY: number

        Vertical scale factor (must be non-zero).

      Returns Shape

      this for chaining.

    • Apply a Mat23 affine transform to the shape's local geometry.

      Parameters

      • matrix: { _inner: any }

        The transformation matrix (must be non-singular; Circles require equiorthogonal).

      Returns Shape

      this for chaining.

    • Translate the shape's local vertices by the given vector (in-place).

      Parameters

      • translation: Vec2

        The displacement vector to apply.

      Returns Shape

      this for chaining.