WorldEntity represents a scrollable world with a viewport. It extends Canvas2DEntity and provides methods for adding blocks, managing collisions, and scrolling the viewport.

WorldEntity

Hierarchy (view full)

Constructors

Properties

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

The action function that defines the entity's behavior.

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

The height of the entity's canvas.

name: string

The name of the entity.

The properties of the world entity.

scene?: Scene
startTimeinMs?: number
tickListeners?: ((time: number, count: number, propertyBag?: IWorldProps) => 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 block to the world.

    Parameters

    • block: ICompositeEntity<any>

      The block to add.

    • OptionalstartTime: number

      The optional start time of the block within the scene (in milliseconds).

    • Optionalduration: number

      The optional duration of the block within the scene (in milliseconds).

    Returns this

    The WorldEntity instance for chaining.

  • Adds multiple blocks to the world.

    Parameters

    Returns this

    The WorldEntity instance for chaining.

  • Adds a collision detector to the entity.

    Type Parameters

    • A
    • B

    Parameters

    • targetKey: string

      The key of the target block.

    • sourceKey: string

      The key of the source block.

    • detectorFn: ((a: A, b: B) => boolean)

      The collision detection function.

        • (a, b): boolean
        • Parameters

          Returns boolean

    • onCollision: ((target: A, source: B) => void)

      The callback function to be executed when a collision is detected.

        • (target, source): void
        • Parameters

          • target: A
          • source: B

          Returns void

    Returns void

  • 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

  • Checks for collisions between the registered collision detectors.

    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

  • 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.

  • Scrolls the viewport horizontally.

    Parameters

    • x: number

      The new x-coordinate of the viewport.

    Returns void

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

    Parameters

    • timeStamp: number

      The current timestamp in the animation.

    Returns void