Class Canvas2DEntity<T>

Type Parameters

  • T

Hierarchy (view full)

Implements

Constructors

  • Creates a new Entity.

    Type Parameters

    • T

    Parameters

    • name: string

      The key or identifier for the entity.

    • Optionalprops: T

      The properties for the entity.

    • Optionalaction: ((time: number, ctx: CanvasRenderingContext2D, properties: T, sequence?: Sequence, entity?: Canvas2DEntity<T>) => void)

      The action function that defines the entity's behavior.

        • (time, ctx, properties, sequence?, entity?): void
        • Parameters

          Returns void

    • OptionalstartTimeinMs: number
    • OptionaldurationInMs: number
    • Optionalw: number

      The width of the entity's canvas.

    • Optionalh: number

      The height of the entity's canvas.

    Returns Canvas2DEntity<T>

Properties

action?: ((time: number, ctx: CanvasRenderingContext2D, properties: T, sequence?: Sequence, entity?: Canvas2DEntity<T>) => void)

The action function that defines the entity's behavior.

barListeners?: ((time: number, count: number, propertyBag?: T) => void)[] = []
beatListeners?: ((time: number, count: number, propertyBag?: T) => void)[] = []
canvas: HTMLCanvasElement
ctx: CanvasRenderingContext2D
durationInMs?: number
h?: number

The height of the entity's canvas.

name: string

The key or identifier for the entity.

props?: T

The properties for the entity.

scene?: Scene
startTimeinMs?: number
tickListeners?: ((time: number, count: number, propertyBag?: T) => void)[] = []
transitionIn?: ((ctx: CanvasRenderingContext2D, progress: number) => void)
transitionOut?: ((ctx: CanvasRenderingContext2D, progress: number) => void)
w?: number

The width of the entity's canvas.

Methods

  • Adds a post-processing function to the entity.

    Parameters

    • processor: ((ctx: CanvasRenderingContext2D, sequence: Sequence) => void)

      The post-processing function to add.

        • (ctx, sequence): void
        • Parameters

          • ctx: CanvasRenderingContext2D
          • sequence: Sequence

          Returns void

    Returns void

  • Copies the entity's canvas to the target canvas and applies post-processors.

    Parameters

    • targetCanvas: HTMLCanvasElement

      The target canvas to copy to.

    • sequence: Sequence

      The Sequence instance.

    Returns void

  • Retrieves the Scene instance associated with the entity.

    Returns undefined | Scene

    The Sequence instance if available, otherwise null.

  • Adds an event listener for when a bar is complete.

    Type Parameters

    • T

    Parameters

    • listener: ((ts: number, count: number, propertyBag?: T) => void)

      The function to call when a bar is complete.

        • (ts, count, propertyBag?): void
        • Parameters

          • ts: number
          • count: number
          • OptionalpropertyBag: T

          Returns void

    Returns this

    The Entity instance for chaining.

  • Adds an event listener for when a beat occurs.

    Type Parameters

    • T

    Parameters

    • listener: ((time: number, count: number, propertyBag?: T) => void)

      The function to call when a beat occurs.

        • (time, count, propertyBag?): void
        • Parameters

          • time: number
          • count: number
          • OptionalpropertyBag: T

          Returns void

    Returns this

    The Entity instance for chaining.

  • Adds an event listener for when a tick occurs.

    Type Parameters

    • T

    Parameters

    • listener: ((time: number, count: number, propertyBag?: T) => void)

      The function to call when a tick occurs.

        • (time, count, propertyBag?): void
        • Parameters

          • time: number
          • count: number
          • OptionalpropertyBag: T

          Returns void

    Returns this

    The Entity instance for chaining.

  • Updates the entity's state, clears the canvas, and calls the action function.

    Parameters

    • timeStamp: number

      The current timestamp in the animation.

    Returns void