@kayelaa/canvas API - v0.2.15
    Preparing search index...

    Class LeaSceneII

    Container for a collection of entities, handling update/draw loops and z-order sorting.

    Hierarchy (View Summary)

    • LeaEventEmitter<{ update: [number]; draw: [CanvasRenderingContext2D] }>
      • LeaSceneII
    Index

    Constructors

    Properties

    listenerMap: Map<"draw" | "update", Listener<any[]>[]> = ...
    name: string = ""

    Unique name of the scene.

    entities: Map<string, LeaEntityII> = ...

    Map of entities by name.

    paused: boolean = true

    Whether updates and drawing are paused.

    Methods

    • Registers a listener for the specified event.

      Type Parameters

      • K extends "draw" | "update"

        Event name

      Parameters

      • event: K

        The name of the event

      • listener: (...args: { update: [number]; draw: [CanvasRenderingContext2D] }[K]) => void

        The callback to invoke when the event is emitted

      Returns this

      This emitter for chaining

    • Registers a one-time listener for the specified event.

      The listener is automatically removed after the first invocation.

      Type Parameters

      • K extends "draw" | "update"

        Event name

      Parameters

      • event: K

        The name of the event

      • listener: (...args: { update: [number]; draw: [CanvasRenderingContext2D] }[K]) => void

        The callback to invoke once

      Returns this

      This emitter for chaining

    • Removes a listener for the specified event.

      Type Parameters

      • K extends "draw" | "update"

        Event name

      Parameters

      • event: K

        The name of the event

      • listener: (...args: { update: [number]; draw: [CanvasRenderingContext2D] }[K]) => void

        The callback to remove

      Returns this

      This emitter for chaining

    • Emits an event, invoking all registered listeners with the provided arguments.

      If the event is "error" and no listeners are registered, the first argument (the error) will be thrown.

      Type Parameters

      • K extends "draw" | "update"

        Event name

      Parameters

      • event: K

        The name of the event to emit

      • ...args: { update: [number]; draw: [CanvasRenderingContext2D] }[K]

        Arguments to pass to listeners

      Returns boolean

      true if any listeners were invoked, false otherwise

    • Removes all listeners for the specified event, or all listeners if no event is provided.

      Type Parameters

      • K extends "draw" | "update"

        Event name

      Parameters

      • Optionalevent: K

        Optional event name to clear listeners for

      Returns LeaSceneII

      This emitter for chaining

    • Returns the number of listeners registered for the specified event.

      Type Parameters

      • K extends "draw" | "update"

        Event name

      Parameters

      • event: K

        The event to count listeners for

      Returns number

      The number of registered listeners

    • Updates all non-paused entities in the scene.

      Parameters

      • delta: number

        Time since last update in seconds

      Returns void

    • Draws all entities in z-order (higher z = drawn later).

      Parameters

      • ctx: CanvasRenderingContext2D

        The 2D rendering context

      Returns void

    • Adds an entity to the scene.

      Parameters

      • entity: any

        The entity to add

      Returns void

      If the entity has no name

    • Removes an entity from the scene by name.

      Parameters

      • entity: any

        The entity to remove

      Returns void

    • Retrieves an entity by name.

      Parameters

      • name: string

        The name of the entity

      Returns LeaEntityII

      The entity, or undefined if not found