jetlag2d
    Preparing search index...

    Class CollectableBehavior

    CollectableBehavior is most easily thought of as a coin. When an eligible actor collides with it, it usually disappears, and some counter gets updated.

    Hierarchy (View Summary)

    Index
    • Construct a CollectableBehavior

      Parameters

      • cfg: {
            eligible?: (other: Actor) => boolean;
            onCollect: string | ((g: Actor, collector: Actor) => boolean);
            team?: number;
        }
        • Optionaleligible?: (other: Actor) => boolean

          Which actors can collect this (default: only player-controlled actors)

        • onCollect: string | ((g: Actor, collector: Actor) => boolean)

          Code to run when an eligible actor collects this, or the name of a score counter to increment by one

        • Optionalteam?: number

          The team this actor belongs to (default 0)

      Returns CollectableBehavior

    _actor?: Actor<unknown>

    The actor associated with this Behavior

    eligible: (other: Actor) => boolean

    Which actors are allowed to collect this? Defaults to player-controlled actors only.

    onCollect: string | ((g: Actor, collector: Actor) => boolean)

    The code to run when an eligible actor collects this, or the name of a score counter to increment by one.

    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