jetlag2d
    Preparing search index...

    Class Actor<D>

    Actor is the main entity of the game. Pretty much everything on the stage is an actor.

    An actor can carry data of type D in its data field. D will be inferred by the data argument provided to the Actor constructor. If you omit it, data will have type unknown.

    Type Parameters

    • D = unknown
    Index
    • Create an Actor

      Type Parameters

      • D = unknown

      Parameters

      • config: ActorConfig & { data: D }

        Everything that can be given to the Actor constructor, other than data, which has its own rules (see the constructor)

        • appearance: AppearanceComponent | AppearanceComponent[]

          What the actor looks like: one appearance component, or an array of them, drawn in order. An empty array is an error.

        • Optionalbehaviors?: Behavior | Behavior[]

          What the actor does when it touches other actors: one behavior, or an array of them. If omitted, the actor has a PassiveBehavior, so it doesn't collide with anything

        • Optionalgestures?: GestureHandlers

          Functions to run when the player touches, pans, swipes, or hovers over the actor

        • Optionalmovement?: MovementComponent

          How the actor moves. If omitted, the actor only moves when physics moves it

        • OptionalonDisappear?: (a: Actor) => void

          Code to run when the actor disappears

        • rigidBody: RigidBodyComponent

          The physical body (BoxBody, CircleBody, or PolygonBody). It also decides which scene the actor lives in. Required, because every actor needs a place in the world.

        • Optionalsounds?: SoundEffectComponent

          The sounds to play for this actor, such as when it disappears

        • data: D

          Data to attach as actor.data. It is required if D is anything other than unknown, so that actor.data always has the type it claims

      Returns Actor<D>

    • Type Parameters

      • D = unknown

      Parameters

      • config: ActorConfig & (unknown extends D ? { data?: undefined } : never)

      Returns Actor<D>

    appearance: AppearanceComponent[]

    The visual representation of this Actor within the game

    behaviors: Behavior[]

    The behaviors that this Actor exhibits within the game. An Actor can carry more than one -- e.g. a Hero-like actor typically has a PlayerControlBehavior, a JumpBehavior, and a HealthBehavior all at once.

    data: D

    Data that is specific to this actor, of whatever type was given at construction time. It is strongly typed.

    gestures: GestureHandlers

    A set of functions describing how the Actor should respond to gestures.

    id: number = ...

    A unique, creation-order id. Used to deterministically break ties when two Actors' Behaviors both might react to the same contact: whichever Actor has the lower id is given the first chance to react.

    onDisappear: ((a: Actor) => void) | undefined

    Code to run when the actor disappears

    prerenderTasks: ((elapsedMs: number, actor: Actor) => void)[] = []

    Tasks to run immediately before every render of this Actor, in the order that they were added. Each task receives the time since the last render, and the Actor. They are useful for any rule that depends on something that changes every frame, like "am I behind the camera?".

    A physical context for the Actor. This is necessary if the Actor will move, participate in collisions, or receive gesture inputs.

    scene: Scene

    The scene where the Actor exists

    The packet of information describing the audio aspects of this Actor

    The current state of this Actor

    • get enabled(): boolean

      Is this Actor visible and able to interact with the world?

      Returns boolean

    • set enabled(val: boolean): void

      Set whether this Actor is visible and able to interact with the world

      Parameters

      • val: boolean

      Returns void

    • Change the size of an Actor, keeping its center unchanged

      Parameters

      • scale: number

        The factor by which to scale the actor's dimensions. Must be >0. 1 means no change, a fraction means shrink, and a number >1 means grow.

      Returns void