jetlag2d
    Preparing search index...

    Class TouchPlateBehavior<Other>

    TouchPlateBehavior is for an actor who doesn't register Box2D collisions, but runs code when something enters it (onEnter) and when that something leaves it (onLeave). It's like a pressure plate.

    Other is a trick for avoiding type casts: If the constructor's eligible() argument is a type guard (returns other is Other instead of returning boolean), then onEnter and onLeave work with Other without having to cast to Other first.

    Type Parameters

    Hierarchy (View Summary)

    Index
    • Construct a TouchPlateBehavior. If eligible is a type guard, such as (a: Actor): a is Bug => a.data instanceof BugData, then onEnter and onLeave are given an actor of that type, so they don't need to cast.

      Type Parameters

      Parameters

      • cfg: {
            eligible: (other: Actor) => other is Other;
            onEnter?: (self: Actor, other: Other) => void;
            onLeave?: (self: Actor, other: Other) => void;
            team?: number;
        }
        • eligible: (other: Actor) => other is Other

          Which actors this reacts to (default: only player-controlled actors)

        • OptionalonEnter?: (self: Actor, other: Other) => void

          The code to run when an eligible actor enters this (that is, starts touching it)

        • OptionalonLeave?: (self: Actor, other: Other) => void

          The code to run when an eligible actor leaves this (that is, stops touching it)

        • Optionalteam?: number

          The team this actor belongs to (default 0)

      Returns TouchPlateBehavior<Other>

    • Type Parameters

      Parameters

      • cfg: {
            eligible?: (other: Actor) => boolean;
            onEnter?: (self: Actor, other: Actor) => void;
            onLeave?: (self: Actor, other: Actor) => void;
            team?: number;
        }

      Returns TouchPlateBehavior<Other>

    _actor?: Actor<unknown>

    The actor associated with this Behavior

    eligible: (other: Actor) => boolean

    Which actors does this affect? Defaults to player-controlled actors only.

    onEnter: (self: Actor, other: Other) => void

    The code to run when an eligible actor enters this (starts touching it)

    onLeave: (self: Actor, other: Other) => void

    The code to run when an eligible actor stops touching this

    team: number = 0

    Which "team" this Behavior belongs to. A team is just a number, and for the most part it's only when user code consults teams that teams have meaning. The only exception is that HazardBehavior uses team to prevent team attack damage.

    • Turn off physical collisions for actor. Used by Behaviors that are only ever passed through, not physically collided with, like coins.

      Parameters

      • actor: Actor<unknown> | undefined

        The actor being attached (may be undefined, if this Behavior is being detached)

      Returns void

    • If actor's body isn't dynamic, warn and upgrade it to dynamic. Used by every Behavior whose whole point requires a dynamic body (e.g. setVelocity/forces actually doing something).

      Parameters

      • actor: Actor<unknown> | undefined

        The actor being attached (may be undefined, if this Behavior is being detached)

      • behaviorName: string

        The name to use in the warning message

      Returns void