nape-js API
    Preparing search index...

    Class CbType

    Callback type tag — used to label bodies, shapes, and constraints so that listeners can selectively respond to interactions involving specific objects.

    Objects can carry multiple CbTypes (via their cbTypes list). Listeners match against those types using OptionType include/exclude filters, or using the built-in singletons (ANY_BODY, ANY_SHAPE, etc.).

    const playerType = new CbType();
    body.cbTypes.add(playerType);

    const listener = new InteractionListener(
    CbEvent.BEGIN,
    InteractionType.COLLISION,
    playerType,
    null,
    (cb) => { console.log('player hit something'); },
    );
    space.listeners.add(listener);

    Converted from nape-compiled.js lines 689–770.

    Index

    Constructors

    Accessors

    • get constraints(): object

      Live list of all constraints currently tagged with this CbType. Read-only.

      Returns object

    • get interactors(): object

      Live list of all interactors (bodies/shapes/compounds) currently tagged with this CbType. Read-only.

      Returns object

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

      Arbitrary user data attached to this CbType.

      Lazily initialized to {} on first access. Use to store application-level metadata associated with the type.

      Returns Record<string, unknown>

    • get ANY_CONSTRAINT(): CbType

      Built-in type automatically assigned to every Constraint.

      Note: Constraints do NOT automatically carry ANY_CONSTRAINT in their cbTypes list — you must add a custom CbType manually if you want to filter constraint events.

      Returns CbType

    Methods