nape-js API
    Preparing search index...

    Class PreListener

    Pre-interaction listener — called before collision resolution each step.

    The handler receives a PreCallback and returns a PreFlag that determines whether and how the interaction should be processed:

    • PreFlag.ACCEPT — resolve the interaction normally (default).
    • PreFlag.IGNORE — suppress the interaction permanently (until next BEGIN).
    • PreFlag.ACCEPT_ONCE — accept this step, then revert to default.
    • PreFlag.IGNORE_ONCE — ignore this step only.

    Returning null is equivalent to ACCEPT.

    The event is always CbEvent.PRE and cannot be changed.

    Caching comes from the returned flag: ACCEPT / IGNORE are remembered and the handler is not called again until the next BEGIN; the _ONCE variants re-run it every step.

    Pure mode: pure = true promises the handler's result depends only on the pair, so the bodies may fall asleep while it returns a _ONCE flag. A non-pure listener (the default) keeps both bodies awake so it keeps running. Only use pure when the handler will always return the same flag for a given pair.

    const preListener = new PreListener(
    InteractionType.COLLISION,
    playerType,
    onewayPlatformType,
    (cb) => cb.arbiter.collisionArbiter!.normal.y > 0
    ? PreFlag.ACCEPT
    : PreFlag.IGNORE,
    );
    space.listeners.add(preListener);

    Hierarchy (View Summary)

    Index
    • get precedence(): number

      Execution priority of this listener relative to other listeners for the same event and objects. The direction depends on the listener type (inherited from Haxe nape):

      • BodyListener / ConstraintListener: higher values run first; on a tie the listener added last runs first.
      • InteractionListener / PreListener: lower values run first; on a tie the listener added first runs first. When several PreListeners return a flag for the same pair the last one called wins — so the highest precedence has the final say.

      Returns number

      0

    • set precedence(precedence: number): void

      Parameters

      • precedence: number

      Returns void

    • get pure(): boolean

      When true, the engine caches the handler return value and does not re-invoke the handler until the cached result is invalidated.

      Only use pure mode when the handler always returns the same flag for a given pair of interactors. Setting pure to false immediately invalidates any cached result.

      Returns boolean

    • set pure(pure: boolean): void

      Parameters

      • pure: boolean

      Returns void